Solved

Linux string manipulation.

Posted on 2010-08-24
7
519 Views
Last Modified: 2013-12-21

I am looking for a Linux command or script that retrieves a particular string from a file and write it to another file.
 The file to be searched is a log file that may contain e-mail addresses in the following format “no.reply+something+thisstring@domain.com”
I need to retrieve "thisstring" wherever found and write it to another file.

My approach was to search for “no.reply+” substring using grep command and then use another command that retrieves the string between the second + sign and the @ sign, but I need help writhing the complete command.

Any help is appreciating it.

Thanks in advance.
0
Comment
Question by:AbdellahT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:mhenry20
ID: 33514986
grep "no.reply+" filename | cut -d "+" -f 3
0
 
LVL 4

Expert Comment

by:mhenry20
ID: 33515016
More information cut:

-d = delimeter in this case the + sign.
-f = field to return in this case the third field.

So -f 1 = no.reply
-f 2 = something
and
-f 3 = thisstring@domain.com

in case you need to adjust fields.
0
 

Author Comment

by:AbdellahT
ID: 33515225
I ran the command but the result are lines start with thisstring@domain.com ..........
How can I make the command to return only "thisstring"?
Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
mhenry20 earned 500 total points
ID: 33515371
grep "no.reply+" filename | cut -d "+" -f 3|cut -d "@" -f 1

That will cut again at the @ sign and return the first field. thisstring.
0
 

Author Comment

by:AbdellahT
ID: 33516261
Groovy.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33925128
grep "no.reply+" under some systems might behave as egrep and match no.replyyyyyyyyyy

you should fgrep for exact string matching.
0
 
LVL 3

Expert Comment

by:T1750
ID: 33925135
even if it doesn't matter due to the input, it makes your intention clearer in the code.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Write to Specific line in a file 15 115
RoboCopy to Changing External Drives 2 61
AWS- KeepAlived notify script not working 23 112
AWK How do I reorder the columns in a csv 7 61
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question