awk (gawk) grep & columns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk (gawk) grep & columns
# 1  
Old 11-06-2010
awk (gawk) grep & columns

Hi,
I'm working with gawk (on DOS) today.
A goal is: find a string for-instance '123', cut a line in two columns and write second one. The problem is: command line works OK, awk file doesn't. But I would like to work with file because there are many strings to find.

input:
Quote:
Jane Doe1
Jane 123 Main
Any where
Jane Doe2
line command:
Quote:
</> awk "{FS=\"Jane \"}/123/{print $2}" data.txt
123 Main
awk file:
Quote:
{ FS="Jane " }
/123/
{print $2}
Quote:
</> awk -f prog.awk data.txt

Doe1
Jane 123 Main
123 Main

Doe2
# 2  
Old 11-06-2010
The print command must be on the same line with the condition:
Code:
{ FS="Jane " }
/123/{print $2}

# 3  
Old 11-06-2010
Thx a lot, Franklin. So simple now, but I could not find it.
# 4  
Old 11-06-2010
or:

Code:
BEGIN{ FS="Jane " } \
/123/ \
{print $2}

# 5  
Old 11-08-2010
But. Then I'd like to add/find one string more...
Quote:
{ FS="Jane " }
/123/ {print $2}
{ FS="Doe" }
/Doe2/ {print $2}
But it gives me only last result/print ?!?

My problem is namely one (even more) large file and at least twelve strings to find in it (them). I can manage this with twelve awk commands, but I'd like to add all into one awk command file.
And last, I'd like to put results into columns as:
- first string first column, second string second column,...
and
- first file first row, second file, second row,...
Many wishes...

---------- Post updated at 12:58 PM ---------- Previous update was at 09:48 AM ----------

I found it (silly me Smilie).
Quote:
{ FS="Jane ||Doe" }
/123/ {print $2}
/Doe2/ {print $2}
First one ok. But second one: to put results into columns instead of one by one into rows, is still in questionSmilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find && Gawk

I have several of the same file names(facts) in different directories that are "|" pipe delimited and are like such: xxx.xxx.xxx.xx1|blah|a|host|FQDN|domain||extra stuff blah1 blah2 host xxx.xxx.xxx.xx2|blah|a|host|FQDN|domain||extra stuff blah1 blah2 host... (2 Replies)
Discussion started by: metallica1973
2 Replies

2. Shell Programming and Scripting

Include information in certain columns using grep and awk

HI all, I have data in a file that looks like this: 1 HOW _ NNP NNP _ 3 nn _ _ 2 DRUGS _ NNP NNP _ 3 nn _ _ 3 ACT _ NNP NNP _ 0 null _ _ 4 : _ ... (3 Replies)
Discussion started by: owwow14
3 Replies

3. Shell Programming and Scripting

Compare intervals (columns) from two files (awk, grep, Perl?)

Hi dear users, I need to compare numeric columns in two files. These files have the following structure. K.txt (4 columns) A001 chr21 9805831 9846011 A002 chr21 9806202 9846263 A003 chr21 9887188 9988593 A003 chr21 9887188 ... (2 Replies)
Discussion started by: jcvivar
2 Replies

4. Shell Programming and Scripting

grep/awk to only print lines with two columns in a file

Hey, Need some help for command to print only lines with two columns in a file abc 111 cde 222 fgh ijk 2 klm 12 23 nop want the ouput to be abc 111 cde 222 ijk 2 Thanks a lot in advance!!! (3 Replies)
Discussion started by: leo.maveriick
3 Replies

5. Shell Programming and Scripting

trouble with gawk and columns

I am trying to make a script that would take the highest value of each columns for example cat file 0 0 0 0 0 8 9 1 3 8 3 9 7 7 7 7 the results would be 7 8 9 9 I found this code, and it takes the highest value with a... (2 Replies)
Discussion started by: gengar
2 Replies

6. Shell Programming and Scripting

Display output as columns using grep/awk/sed

I have several files with say something like cat sparrow I can grep for "cat" and "sparrow" and usually the output is one below the other cat sparrow How can I view these as columns say Pets Birds cat sparrow Would be great if this can be on command line using awk or... (1 Reply)
Discussion started by: gubbu
1 Replies

7. Shell Programming and Scripting

grep & awk

Hi all, I'm figuring on how to grep only specific data I want below: Bin Total % ----- ------- ----- 1 15 42.9 Bin Total % ----- ------- ----- 2 15 ... (3 Replies)
Discussion started by: *Jess*
3 Replies

8. Shell Programming and Scripting

gawk - reading two files & re arrange the columns

Hi, I am trying to read 2 files and writing to the 3rd file if I find the same elements in 2 files. my first file is 1 0 kb12124819 766409 1.586e-01 1 0 kb17160939 773886 8.674e-01 1 0 kb4475691 836671 8.142e-01 1 0 ... (2 Replies)
Discussion started by: ezhil01
2 Replies

9. Shell Programming and Scripting

Remove lines, Sorted with Time based columns using AWK & SORT

Hi having a file as follows MediaErr.log 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:12:16 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:22:47 84 Server1 Policy1 Schedule1 master1 05/08/2008 03:41:26 84 Server1 Policy1 ... (1 Reply)
Discussion started by: karthikn7974
1 Replies

10. Shell Programming and Scripting

awk / grep / Prints all columns except the first one

I have the a file with the following data. File Content. 1249 snf06.3.0 sw version 1.1 code MD5 192F MD4 MD3 1248 sns06.3.0 sw version 1.1 code MD5 192F MD12 1250 sns06.3.0 sw version 1.1 code MD5 192F0\ MD8 1241 sns06.3.0 sw code MD5 19 1243 sn06.3.0 sw version 1.1 code MD5 19 12... (17 Replies)
Discussion started by: knijjar
17 Replies
Login or Register to Ask a Question