display file where 4th field = 200704


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting display file where 4th field = 200704
# 1  
Old 06-26-2008
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
# 2  
Old 06-27-2008
try:
Code:
awk -F '|' '{ if($4 == "200704") { print } }' filename

# 3  
Old 06-27-2008
Quote:
Originally Posted by Yogesh Sawant
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
# 4  
Old 06-27-2008
$ 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?
# 5  
Old 06-27-2008
Quote:
Originally Posted by eBay
$ 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
# 6  
Old 06-27-2008
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  
Old 06-27-2008
ratnakar

raja this also works

cat one.txt | awk '{print $1;}' | awk -F"|" '{if($3==2004)print $0}'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

2. Shell Programming and Scripting

How to extract 4th field if numerics?

I have a file which contains fields comma separated & with each field surrounded by quotes. The 4th field contains either a serial number, the text ABC, the text XYZ or it's blank. I want to only extract records which have a serial number. Here's some sample data: > cat myfile... (4 Replies)
Discussion started by: CHoggarth
4 Replies

3. Shell Programming and Scripting

perl script to split the text file after every 4th field

I had a text file(comma seperated values) which contains as below 196237,ram,25-May-06,ram.kiran@xyz.com,204183,Pavan,4-Jun-07,Pavan.Desai@xyz.com,237107,ram Chandra,15-Mar-10,ram.krishna@xyz.com ... (3 Replies)
Discussion started by: giridhar276
3 Replies

4. Shell Programming and Scripting

How to extract a field from ls-l command and display?

So I want to put a line at the end of my script which greps for keywords from syslog.log that outputs the following after it is done: "This file was last modified on (thisdate)" I know I can use the following to get the date: rtidsvb(izivanov):/home/izivanov> ll /var/adm/syslog/syslog.log ... (4 Replies)
Discussion started by: zixzix01
4 Replies

5. Shell Programming and Scripting

Read File and Display The Count of a particular field

Hi Mates, I require help in the following: I have the following file snmp.txt Wed Mar 2 16:02:39 SGT 2011 Class : mmTrapBladeS origin : 10.0.0.0 hostname : 10.0.0.2 msg : IBM Blade Alert: Calendar Index : 10.0.0.2-IBMBLADE Fri Mar 4 07:10:54 SGT 2011 Class : mmTrapBladeS... (2 Replies)
Discussion started by: dbashyam
2 Replies

6. Shell Programming and Scripting

How to only display lines where a field has the highest number?

Hello Wondering if anybody can advise me how I can sort the below file so it only displays lines with the latest versions of an object? As you'll see some of the scripts listed in my file have more than one version number (version number is after the file extension). E.g. cdm_bri.pkb has... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

7. Shell Programming and Scripting

Replace 4th field if null

Hi .. Can some one please suggest me how to replace 4th field(column) of a .csv file with "NA" if it is null. Input file data: |A|21|B1||1.1| |A|21|C|RAGH|1.1| |A|21|D1||1.1| |A|21|C|YES|1.1 Expected Output |A|21|B1|NA|1.1| |A|22|C|RAGH|1.1| |B|23|D1|NA|1.1| |A|24|C|YES|1.1| Thank... (4 Replies)
Discussion started by: pasupuleti81
4 Replies

8. UNIX for Dummies Questions & Answers

Awk help needed for display particular field alone for searching pattern

Hi, I have a requirement for taking an particular number in a log file. if i grep for the particular string it will retrieve the entire line for the particular string. but i want to display only the string from each line which i am searching for, Note: The searching field varies its position... (3 Replies)
Discussion started by: senthilkumar_ak
3 Replies

9. Shell Programming and Scripting

using awk make an field as 5 digit and display

using awk convert 3 rd fileld of file as 5 digit and then display changed file. like 1 2 23445 3452 3343 3 5 6 6 ================ o/p:- 1 2 23445 3452 03343 3 5 00006 6 (1 Reply)
Discussion started by: RahulJoshi
1 Replies

10. AIX

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 (4 Replies)
Discussion started by: vasuarjula
4 Replies
Login or Register to Ask a Question