![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| display file where 4th field = 200704 | vasuarjula | AIX | 4 | 06-27-2008 12:04 AM |
| How to uniq third field in a file | babycakes | UNIX for Dummies Questions & Answers | 1 | 02-01-2008 12:52 AM |
| delete a field along with delimiter in the whole file | dsravan | Shell Programming and Scripting | 5 | 11-01-2007 10:40 PM |
| select last field from a file | kykyboss | Shell Programming and Scripting | 3 | 11-14-2006 07:15 AM |
| Append a field to the end of each line of a file based on searching another file. | ultimate | Shell Programming and Scripting | 2 | 03-29-2005 07:21 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
display file where 4th field = 200704
Hello
I have a file which is pipe delimited. The 4 th field has value like 200704 or 200705 etc. Now i have to get only those records where 4th field is 200704 How can i do this? I have to get the whole record where 4th field = 200704 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
try:
Code:
awk -F '|' '{ if($4 == "200704") { print } }' filename
|
|
#3
|
|||
|
|||
|
Quote:
not working. In the output file, for all the records, 4th field is replaced as 20074. But how can i search in the file |
|
#4
|
||||
|
||||
|
$ cat d
mark|64|200710|guitar mike|61|200605|bass pete|65|200704|drums lisa|67|200705|vocals $ awk -F '|' '{if($3=="200605") {print} }' d mike|61|200605|bass $ Works on my iMac OK. Did you use two equal signs in the test? |
|
#5
|
|||
|
|||
|
Quote:
I have also tested this on test data, its working. But when i run the same on my data which has 90 fields in each record, if value is found it displays only 8 fields. The records is searched corectly, but when displaying many fields are truncated. Let me know if i have to add any code in this |
|
#6
|
|||
|
|||
|
ratnakar
raja this will work try it
grep "^[0-9a-zA-Z]*|[0-9a-zA-Z]*|[0-9a-zA-Z]*|[0-9a-zA-Z]*|2004" < test.txt >> test1.txt |
|
#7
|
|||
|
|||
|
ratnakar
raja this also works
cat one.txt | awk '{print $1;}' | awk -F"|" '{if($3==2004)print $0}' |
|||
| Google The UNIX and Linux Forums |