UNIX Shell Script Help for pattern search

Hi
Need help for below coding scenario.

I have a file with say 4 lines as below.

DEFINE JOB TPT_LOAD_INTO_EMP_DET
( TDPID = @TPT_TDSERVER , USERNAME = @TPT_TDUSER ) ;
( 'DROP TABLE '||@TPT_WRKDB ||'.LOG_'||@TPT_TGT ||' ; ') ,
SELECT * FROM OPERATOR (FILE_READER[1]) ; ) ;

Now I want to find all those words separately from every line starting with "@" and ending with " " and write them in a file

Example: my out file should contain

TPT_TDSERVER
TPT_TDUSER
TPT_WRKDB
TPT_TGT

Please help me as it is urgent. I tried to achieve this using grep, awk and sed but could not reach to the expected result.

Thanks in advance
Santanu

Please use code tags as required by forum rules!

And, show us your vain attempts so we can help.

A small sed-loop chopping off one word after the other:

sed -n ':loop
/@/ {
  s/^[^@]*//
  s/^@\([^ ][^ ]*\) /\1\n/
  P
  D
  b loop
}' /path/to/your/file

I hope this helps.

bakunin

Try:

awk 'NR>1{print $1}' RS=@ file>newfile

----

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums

Try also

grep -o "@[^ ]* " file
@TPT_TDSERVER 
@TPT_TDUSER 
@TPT_WRKDB 
@TPT_TGT 

If the "@" needs to go away, pipe it through tr -d @

Thanks to all of you. What I tried initially was ,

  1. grep -o '@' <full file name>
  2. grep "@" <full file name> | awk -F 'FS' 'BEGIN{FS="@"}{for (i=1;i<=NF;i++) {printf $i FS}}'

and in sed it was not so handy.

I was not able to get the result before which I am getting now after help from you guys. Thanks again.

Santanu