How to get the next word which falls just after a keyword?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the next word which falls just after a keyword?
# 1  
Old 05-06-2012
How to get the next word which falls just after a keyword?

Hi friends,
i just want to know the command though which i can get the next word which comes just after a particluar keyword. For example:
suppose text.out is file which contains a pl/sql procedure . i want to find out the word which falls just after the "table1" keyword.

Thank you very much in advance
# 2  
Old 05-06-2012
Please do not leave people guessing. Show a representative sample of input, desired output, attempts at a solution and specify what OS and versions are being used.
# 3  
Old 05-06-2012
@Scrutinizer: i have not written any code because i dont know the solution.
suppose a text file contains the following code"
Code:
SELECT  
PI.BUS_APPL_KEY_ID, 
A.PORTFO_TIER_KEY_ID, A.PORTFO_TIER_NAT_ID, A.PA_LOAN_NAT_ID, 
A.CARD_PROD_KEY_ID, A.CARD_PROD_NAT_ID
FROM (SELECT DISTINCT 
  TRWBE_ST.PORTFO_TIER_KEY_ID
FROM
 rrdwst00.TRWBE_ALLOC_REDEMPTION_FACT TRWBE_ST where TRWBE_ST.PA_LOAN_NAT_ID !=0)
 as A
inner join  rrdwst00.TRWPI_PA_LOAN_REIMB_FACT PI
on 
A.PA_LOAN_NAT_ID= PI.PA_LOAN_NAT_ID
and A.REBATE_REWARD_ACCT_NAT_ID=124612528 and A.CM_NAT_ID=410822498

------
i just want to know command which can tell me what is the next word which comes after the "FROM" keyword?

output should be : "rrdwst00.TRWBE_ALLOC_REDEMPTION_FACT TRWBE_ST "


thanks in advance
# 4  
Old 05-06-2012
There are two FROMs. How do we know which to pick?
# 5  
Old 05-07-2012
@Scrutinizer i want both output i.e
(SELECT and "rrdwst00.TRWBE_ALLOC_REDEMPTION_FACT TRWBE_ST " .. thanks in advance

---------- Post updated 05-07-12 at 05:18 AM ---------- Previous update was 05-06-12 at 11:40 AM ----------

anyone please helppppppppppp
# 6  
Old 05-07-2012
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.
# 7  
Old 05-07-2012
Code:
 
$ nawk -v RS="" '{for(i=1;i<=NF-1;i++)if($i~/FROM/){print $(i+1)}}' input.txt
(SELECT
rrdwst00.TRWBE_ALLOC_REDEMPTION_FACT

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to align/sort the column pairs of an csv file, based on keyword word specified in another file?

I have a csv file as shown below, xop_thy 80 avr_njk 50 str_nyu 60 avr_irt 70 str_nhj 60 avr_ngt 50 str_tgt 80 xop_nmg 50 xop_nth 40 cyv_gty 40 cop_thl 40 vir_tyk 80 vir_plo 20 vir_thk 40 ijk_yuc 70 cop_thy 70 ijk_yuc 80 irt_hgt 80 I need to align/sort the csv file based... (7 Replies)
Discussion started by: dineshkumarsrk
7 Replies

2. Shell Programming and Scripting

Need to extract the word after a particular keyword throughout the file..

Hi Everyone, Need help in extracting the hostname from the below output. Expected output: DS-TESTB-GDS-1.TEST.ABC.COM DS-TESTB-GDS-2.TEST.ABC.COM .... ... /tmp $ cat -n /tmp/patchreport 1 /usr/bin/perl /admin/bin/patch/applyPatches.pl --apply_patches... (4 Replies)
Discussion started by: thiyagoo
4 Replies

3. Shell Programming and Scripting

Search for a Keyword in file and replace another keyword or add at the end of line

Hi I want to implement something like this: if( keyword1 exists) then check if(keyword2 exists in the same line) then replace keyword 2 with New_Keyword else Add New_Keyword at the end of line end if eg: Check for Keyword JUNGLE and add/replace... (7 Replies)
Discussion started by: dashing201
7 Replies

4. Shell Programming and Scripting

Value falls between two values from different files

Hi, I have two files cat 1 100 1 110 2 113 4 230 5 334 7 500 8 900 10 I have another file cat 2 100 200 201 300 301 400 401 500 501 600 601 700 (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it?

How to catch a two word keyword which may contain a new line(may include spaces or tab) in it. for example there is a file a.txt. $more a.txt create view as (select from ......... .......... ( select .... ( select ...... .. select only no ((( number ( select end (12 Replies)
Discussion started by: neelmani
12 Replies

6. Shell Programming and Scripting

how to get a worrd which falls after a keyword separated by comma

Hi friends, i have a file which contains all words(including comma) in different line. for example: more file.txt select column1 from table1 , table2 join table3 0n condition i just want to get table2 if there is a comma after table1(as shown in the above case) else dont fetch... (4 Replies)
Discussion started by: neelmani
4 Replies

7. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

8. UNIX for Dummies Questions & Answers

how to find a word in a file that appears next to a given keyword

Hi Experts, I have a file which contains some text. i need to print the word next to a given keyword. Please help. Ex: test.txt ===================== NEXT HOST ===================== AEADBAS001 access-list 1 permit xxxxxxxxxxxxxx ip access-list extended BLA_Outgoing_Filter... (6 Replies)
Discussion started by: mwrg
6 Replies

9. Shell Programming and Scripting

Replace only if the keyword is the first word in every line

How do I replace only if the keyword is at the begining of a line? Code: -- a = “This is a print statement” print a -- What if I want to replace print by #print only in the second line i.e only if the line starts with that keyword. Please help me out. I'm new to SED. -----Post... (5 Replies)
Discussion started by: alexzubin
5 Replies

10. Shell Programming and Scripting

Awk substring falls between two values

Hi guys, hopefully you can give me a hand with this before my monitor has a nasty accident! :mad: I have the following line in a script: awk 'int(substr($1,2,2))>'06' && int(substr($1,2,2))<'08' ' ANYOLDFILE.log ... which when ran against this data file: ... correctly... (3 Replies)
Discussion started by: dlam
3 Replies
Login or Register to Ask a Question