The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-26-2008
Registered User
 

Join Date: Feb 2008
Posts: 16
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
Reply With Quote
Forum Sponsor
  #2  
Old 06-26-2008
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 790
try:
Code:
awk -F '|' '{ if($4 == "200704") { print } }' filename
Reply With Quote
  #3  
Old 06-26-2008
Registered User
 

Join Date: Feb 2008
Posts: 16
Quote:
Originally Posted by Yogesh Sawant View Post
try:
Code:
awk -F '|' '{ if($4 == "200704") { print } }' filename

not working. In the output file, for all the records, 4th field is replaced as 20074. But how can i search in the file
Reply With Quote
  #4  
Old 06-26-2008
eBay's Avatar
Registered User
 

Join Date: Jun 2008
Location: Spokane
Posts: 12
$ 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 te
st?
Reply With Quote
  #5  
Old 06-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 16
Quote:
Originally Posted by eBay View Post
$ 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 te
st?

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
Reply With Quote
  #6  
Old 06-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 2
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
Reply With Quote
  #7  
Old 06-27-2008
Registered User
 

Join Date: Feb 2008
Posts: 2
ratnakar

raja this also works

cat one.txt | awk '{print $1;}' | awk -F"|" '{if($3==2004)print $0}'
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
awk

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0