Grep line to separate column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep line to separate column
# 8  
Old 10-14-2010
Hi, you mean like this:
Code:
awk '/^=001/{if(NR>1)print p; p=$0; next}/\((abc|xyz)\)/{p=p"\t"$0}END{print p}' infile

# 9  
Old 10-14-2010
Hey ya the same way !!

but here when =035 \\$a(abc) is not there in that column its writing =035 \\$a(xyz) in that column?
Code:
=001 abcd002432236      =035 \\$a(abc)32780281  =035 \\$a(xyz)7550102
=001 abcd002432237      =035 \\$a(abc)37909749  =035 \\$a(xyz)8777598
=001 abcd000509975      =035 \\$a(abc)43067318  =035 \\$a(xyz)8749126   =035 \ \\$a(abc)430673199
=001 abcd000509977      =035 \\$a(xyz)8749128 ???
=001 abcd000509977

Please help to explain the script

Last edited by Scott; 10-15-2010 at 06:57 AM.. Reason: Code tags
# 10  
Old 10-14-2010
That is because it is like that in the input file. Your desired output is unclear.
# 11  
Old 10-14-2010
Thanks for the combined script.
Code:
awk '/^=001/{if(NR>1)print p; p=$0; next}/\((abc|xyz)\)/{p=p"\t"$0}END{print p}' infile

can you please explain me the above script.

Thanks a lot

Last edited by Scott; 10-15-2010 at 06:58 AM.. Reason: Code tags
# 12  
Old 10-15-2010
Here you go:
/^=001/If the line begins with "=001" at the beginning of a line
{if(NR>1)print p; p=$0; next}print the previous prepared output line (p), if we are not on the first line; set p to the content of the line ($0);Afterwards read the next line (next) and goto the beginning of the script.
/\((abcpipesymbolxyz)\)/If the line contains parentheses \( and \) and inside these parenthesis the is either the string "abc" or "xyz"
p=p"\t"$0then add the current line at the end of the prepared line separated with a TAB character
END{print p} at the end print the previous prepared output line (p)
# 13  
Old 10-16-2010
Code:
$ ruby -ne 'chomp;$_=($_["=001"]) ? "\n"+$_ : $_ ;print ' file

# 14  
Old 10-18-2010
Hi

Sorry for late reply, I fell and had injury and hence could not come near system. Thanks a lot for your step by step explanation. Thanks again

Sorry kurumi I dont know how to use ruby.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep one column of line

Hi all: I have the following input file: function-v such_as-hash-n 6.5328 function-n such_as-head-n 2.5586 function-a such_as-headphone-n 8.0794 function-n such_as-health-n 3.1938 function-v such_as-healthcare-n 5.2845 function-n such_as-hearing-n 9.5367... (9 Replies)
Discussion started by: owwow14
9 Replies

2. UNIX for Dummies Questions & Answers

Want to separate one column

I have one command which provide following output related to file system and disk space utilization Filesystem kbytes used avail %used Mounted on /dev/lvol3 131072 73407 54088 58% / /abc/lvol1 59797 30314 2350300 ... (8 Replies)
Discussion started by: Nakul_sh
8 Replies

3. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

4. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

How to grep an empty line in a specific column of a file?

Suppose i have the following data : cat file.txt 12431,123334,55353,546646,14342234,4646,35234 123123,3535,123434,132535,1234134,13535,123534 123213,545465,23434,45646,2342345,4656,31243 2355425,2134324,53425,342,35235,23434,234535 3423424,234234,65465,,2344,35436,234524,234... (7 Replies)
Discussion started by: Ravi Tej
7 Replies

6. Shell Programming and Scripting

grep based on pattern in a line and print the column before that

$ cat file.log Message Number = : Sending message 10:50:16^|^reqhdr.dummyid^=^02^|^reqhdr.timezone^=^GMT+05:30^|^DUMMYREQUEST^=^BH||||||||||||||||||$BD|OL|C|V||DummyAcctNo|02||24/12/2011|ST_DDM|DDM||||||||reqUUID110612105016$BT||||||||||||||||||$] Length I have the above line in the... (4 Replies)
Discussion started by: kalidass
4 Replies

7. Shell Programming and Scripting

grep data on 2nd line and 3rd column

How do I grep/check the on-hand value on the second line of show_prod script below? In this case it's a "3". So if it's > 0, then run_this, otherwise, quit. > ./show_prod Product Status Onhand Price shoe OK 3 1.1 (6 Replies)
Discussion started by: joker_789us
6 Replies

8. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

9. Shell Programming and Scripting

print a line containing word in a column using grep

hi, how to print a row which contains a perticular word in its third column using grep, cut, or any thing else. thanks (2 Replies)
Discussion started by: useless79
2 Replies

10. Shell Programming and Scripting

separate out the column

I know "awk -F:" will separate out the column by ":" , now if I what to separate out the column by space also , what can I do ? for example : #ps -ef |grep telnet root 10159 702 0 15:45 ? 00:00:00 in.telnetd: 192.168.0.1 how to separate out the column so that the column as below, ... (6 Replies)
Discussion started by: ust
6 Replies
Login or Register to Ask a Question