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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
mhenry20IT Operations DirectorCommented:
grep "no.reply+" filename | cut -d "+" -f 3
0
 
mhenry20IT Operations DirectorCommented:
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
 
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
mhenry20IT Operations DirectorCommented:
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

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.