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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to get a worrd which falls after a keyword separated by comma
# 1  
Old 06-07-2012
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
HTML Code:
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 anything.
please help.
thanks in advance.
# 2  
Old 06-07-2012
Try:
Code:
perl -ln0e '/table1\n,\n(.*)/&&print $1' file.txt

# 3  
Old 06-07-2012
thanks for your reply bartus. but i am not familiar with the perl commad. will it work in ksh88??i will really appreciate if anyone can give me awk or sed or any similar command. thank you
# 4  
Old 06-07-2012
Perl command will work in your shell, you just have to have Perl installed (which it is in 99% of the cases). Anyway, here is some AWK:
Code:
awk '/table1/{getline;if ($0==",") {getline;print}}' file.txt

This User Gave Thanks to bartus11 For This Post:
# 5  
Old 06-07-2012
I am not sure I understand, you only want to print the "table2" line but only if it is after a "table1" line AND a "," line?

please show two examples of expected output, one if what you want is found and one where not to print (where not found).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to extract fields from a CSV i.e comma separated where some of the fields having comma as value?

can anyone help me!!!! How to I parse the CSV file file name : abc.csv (csv file) The above file containing data like abv,sfs,,hju,',',jkk wff,fst,,rgr,',',rgr ere,edf,erg,',',rgr,rgr I have a requirement like i have to extract different field and assign them into different... (4 Replies)
Discussion started by: J.Jena
4 Replies

2. Shell Programming and Scripting

awk to parse comma separated field and removing comma in between number and double quotes

Hi Experts, Please support I have below data in file in comma seperated, but 4th column is containing comma in between numbers, bcz of which when i tried to parse the file the column 6th value(5049641141) is being removed from the file and value(222.82) in column 5 becoming value of column6. ... (3 Replies)
Discussion started by: as7951
3 Replies

3. Shell Programming and Scripting

Need comma separated output

Hi, I am having the file with server names & its corresponding process, i need your help how to convert into comma separated output between server & app #cat apps.txt Server1 oracle was Server2 http webadmin Server3 tsm db2 My requirement is like below. Server1,oracle/was... (5 Replies)
Discussion started by: ksgnathan
5 Replies

4. UNIX for Dummies Questions & Answers

[solved] Comma separated values to space separated

Hi, I have a large number of files which are written as csv (comma-separated values). Does anyone know of simple sed/awk command do achieve this? Thanks! ---------- Post updated at 10:59 AM ---------- Previous update was at 10:54 AM ---------- Guess I asked this too soon. Found the... (0 Replies)
Discussion started by: lost.identity
0 Replies

5. Shell Programming and Scripting

Need Help - comma inside double quote in comma separated csv,

Hello there, I have a comma separated csv , and all the text field is wrapped by double quote. Issue is some text field contain comma as well inside double quote. so it is difficult to process. Input in the csv file is , 1,234,"abc,12,gh","GH234TY",34 I need output like below,... (8 Replies)
Discussion started by: Uttam Maji
8 Replies

6. Shell Programming and Scripting

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... (7 Replies)
Discussion started by: neelmani
7 Replies

7. Shell Programming and Scripting

Comma separated file

Hi all, I have the following files types: FileA: 100, 23, 33, FileB: 22, 45, 78, and i want to make File C: 100,22 23,45 33,78 any nice suggestions for making it easy. (3 Replies)
Discussion started by: hen1610
3 Replies

8. Shell Programming and Scripting

Help parse comma separated list

I have a list of files with the same name, but they have a different date stamp in the name. I can find the first file, but I need to find the second file. I am using this information to create a variable I use later. Here is a example of how I find the first file. "ls -mr... (11 Replies)
Discussion started by: NoMadBanker
11 Replies

9. Shell Programming and Scripting

Need comma separated processing

I have a file like this OUTLN OPEN Y SCOTT OPEN N USER4 OPEN Y DBSNMP EXPIRED & LOCKED N ... (4 Replies)
Discussion started by: ilugopal
4 Replies
Login or Register to Ask a Question