AbdellahT
asked on
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+thisst
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.
grep "no.reply+" filename | cut -d "+" -f 3
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.
-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.
ASKER
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.
How can I make the command to return only "thisstring"?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Groovy.
grep "no.reply+" under some systems might behave as egrep and match no.replyyyyyyyyyy
you should fgrep for exact string matching.
you should fgrep for exact string matching.
even if it doesn't matter due to the input, it makes your intention clearer in the code.