Extracting data from multiple lines

Hi All,

I am stuck in one step..

I have one file named file.txt having content:

  And SGMT.perd_id = (SELECT cal.fiscal_perd_id  FROM $ODS_TARGT.TIM_DT_CAL_D CAL
FROM $ODS_TARGT.GL_COA_SEGMNT_XREF_A SGMT
SGMT.COA_XREF_TYP_IDN In (SEL COA_XREF_TYP_IDN From $ODS_TARGT.GL_COA_SEGMNT_XREF_TYP_D
 And SGMT.perd_id = (SELECT cal.fiscal_perd_id  FROM $ODS_TARGT.TIM_DT_CAL_D CAL

My requirement is to find the word just next to $ODS_TARGT.

In This case output should be like:

 TIM_DT_CAL_D
GL_COA_SEGMNT_XREF_A
GL_COA_SEGMNT_XREF_TYP_D
TIM_DT_CAL_D

Please provide me the right solution for the same.

Thanking in Advance...

Shilpi,

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.

Additionally, please wrap code, files, input & output/errors in CODE tags, like this:-

to produce the following (fixed character width, space respected):-

This is my code

Not only does it make posts far easier to read, but CODE and ICODE sections respect multiple space and have fixed width characters, which is important for easily seeing input/output requirements.

Thank you.

The UNIX and Linux Forums

Please use code tags as required by forum rules! And, aside, the word "urgent" (even though you misspelled it) is not too well received in these forums.

Any idea/attempt from your side? Did you consider using awk (which should be easy)?

Maybe.

perl -nle '@m = $_ =~ /\$ODS_TARGT\.(\w+)/ and print @m' file.txt
perl -nle '/\$ODS_TARGT\.(\w+)/ and print $1' file.txt

Some more:

sed -n 's/.*$ODS_TARGT\.\([^[:blank:]]*\).*/\1/p' file
perl -nle 'print $1 if /\$ODS_TARGT.(\S*)/' file