Linux string manipulation.


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.
AbdellahTAsked:
Who is Participating?
 
mhenry20Connect With a Mentor Commented:
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
 
mhenry20Commented:
grep "no.reply+" filename | cut -d "+" -f 3
0
 
mhenry20Commented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
AbdellahTAuthor Commented:
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
 
AbdellahTAuthor Commented:
Groovy.
0
 
T1750Commented:
grep "no.reply+" under some systems might behave as egrep and match no.replyyyyyyyyyy

you should fgrep for exact string matching.
0
 
T1750Commented:
even if it doesn't matter due to the input, it makes your intention clearer in the code.
0
All Courses

From novice to tech pro — start learning today.