awk - help needed please


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - help needed please
# 1  
Old 04-12-2013
awk - help needed please

Hi..

have a file as below, appreciate if someone can help on this


Code:
143|500| 10| 23353 22131 23355 23354 23358 23352 23357 23350 23349 23351| RAID5
213|1008| 9| 22419 22412 221 22413 22414 22416 22417 22415 22418| RAID6
1088|500| 5| 22243 22240 22244 22242 22241| RAID5
322|1200| 12| 22199 22193 22191 22202 22200 22198 22192 22195 22197 22196 22194 22201| RAID5
404|1000| 4| 22132 22133 22131 22134| RAID5
192|300| 3| 22610 22609 22611| RAID5
275|500| 8| 23085 23083 23086 23084 23087 23089 23090 23088| RAID5
22133|1024| 9| 24231 24234 24237 24235 24239 24238 24233 24236 24232| RAID6
.....


How do I grep for "22133" which is in the 4th Column , columns are seperated by "|"

Last edited by Scrutinizer; 04-13-2013 at 04:10 AM.. Reason: code tags
# 2  
Old 04-12-2013
You could use AWK. grep alone can also do it, although the regexp is a bit more complicated. If the entire line does not need to be printed, then a simple cut|grep is also an option.

What have you tried?

Regards,
Alister
# 3  
Old 04-12-2013
Thanks For the quick response, I tried
Code:
awk -F"|" '$4~/22133/'

works, but when do the same for 133 get same results
also
Code:
awk -F"|" '$4=="22133"'

..no luck

Last edited by Scrutinizer; 04-13-2013 at 04:10 AM.. Reason: code tags
# 4  
Old 04-12-2013
Try:
Code:
awk -F'|' '$4~/(^| )22133( |$)/'

# 5  
Old 04-13-2013
My guess is one of the following (you already know one of them) is what you want:
Code:
$ awk -F '|' '$4 ~ /22133/' file
404|1000| 4| 22132 22133 22131 22134| RAID5

Code:
$ awk -F '|' '$4 ~ /\<22133\>/' file
404|1000| 4| 22132 22133 22131 22134| RAID5


Last edited by Scrutinizer; 04-13-2013 at 04:10 AM.. Reason: code tags
# 6  
Old 04-13-2013
Quote:
Originally Posted by hanson44
My guess is one of the following (you already know one of them) is what you want:
Code:
$ awk -F '|' '$4 ~ /22133/' file
404|1000| 4| 22132 22133 22131 22134| RAID5

Code:
$ awk -F '|' '$4 ~ /\<22133\>/' file
404|1000| 4| 22132 22133 22131 22134| RAID5

richard0@rediff already explained in the 3rd message in this thread that he wants a full word match; not the partial match provided by your first awk example.

Some versions of awk allow \< and \> to match start of word and end of word, respectively. But, that behavior is not portable. The only utilities in the POSIX standards and the Single UNIX Specifications that are specified to handle \< and \> this way are the BREs used in searches in ex and vi. Since Richard didn't say what OS or version of awk was being used, I chose not to use these extensions.

The ERE in the awk script I provided should do what was requested with any version of awk (except that /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk should be used instead of awk on Solaris/SunOS systems).
# 7  
Old 05-03-2013
Hello Don / Hanson,


Thanks for your help...
This Works..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk help needed

Hi Everyone, i have following in my file 1 2 3 4 5 6 . . 100 and now i want the output as 1 4 7 ..........so on..............97 100 (10 Replies)
Discussion started by: zozoo
10 Replies

2. Shell Programming and Scripting

awk help needed

Hi Experts, I have a file (file 1) with several columns and I need to create 2 files based on the data of 20th column of file 1. Criteria 1 : If the 20th field of file1 is empty , copy the entire records to file 2. I am successfully able to do this with the following awk code : awk... (2 Replies)
Discussion started by: nua7
2 Replies

3. Shell Programming and Scripting

awk help needed

Hi, i have input records as shown below. 4097,Probe3,G10,255,05/17/2011 12:44:03:185,NULL,05/17/2011 12:39:03:180,05/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

4. UNIX for Dummies Questions & Answers

help needed for awk

Dear all, I am new to use unix. I run the following command and got the error. Anyone knows how should I modify the command. Thanks a lot! $ for chr in 'seq 1 23'; do awk 'BEGIN {print "T","pheno";}{print "M",$2}' out_${chr}.map > dat_${chr}.dat; done error message:... (2 Replies)
Discussion started by: forevertl
2 Replies

5. Shell Programming and Scripting

Awk Help needed

hi, I have input file woth records as shown below OCSMRC_OK,7057348733,+0.00,0,18/05/2010 23:42:19,BellMobility,302610000918553,0006056099,B30,686505,686505,OCS_MRC,+49.14,0,0 ,0,0, OCSPPKB_NOK,4163460120,+1.25,0,18/05/2010... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

6. UNIX for Dummies Questions & Answers

Awk help needed

I have a log file monitor script that checks through a log file for a string. I use awk to search the log file, starting at the last checked line, for the specified string and then output the count and the last row number checked. The part of the script that does all the work is here: set --... (6 Replies)
Discussion started by: mglenney
6 Replies

7. Shell Programming and Scripting

help needed in awk

Hi , i have a file a.txt like this: far near veryfar toonear typeset var1=veryfar to extract the text between two strings i use the following command : awk '/far/,$veryfar/' a.txt its not working can nyone tell pls whats wrong in it ? i doubt can we use variable in awk like this... (3 Replies)
Discussion started by: santosh1234
3 Replies

8. Shell Programming and Scripting

awk help needed

How do I alter this command so that it prints only the second comma delimited field from line number 3? Secondly, how do you redirect the output to a variable called TEST? Thanks (cat BATCH007.TXT | awk 'BEGIN { FS = "," } ; {print $2 }') (5 Replies)
Discussion started by: ddurden7
5 Replies

9. Shell Programming and Scripting

awk help needed

I am trying to write a script that will parse out the e-mail address of a person from the name of a file in a directory. Example: filename is: /home/myname/first.middle.last@email.com.xls I want to extract just the email address and mail the file to that address. I want to send the... (6 Replies)
Discussion started by: Drenhead
6 Replies

10. Shell Programming and Scripting

awk help needed.

Dear All, I want to compare column 3 and column 4 of files(File1 and File2) and want to get the matched records in one file and rejected records in another file.I have tried an awk script,but as Iam not good in it,I cant able to continue.Can anyone help me in this one. File 1... (0 Replies)
Discussion started by: cskumar
0 Replies
Login or Register to Ask a Question