Filter record from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filter record from a file
# 1  
Old 04-21-2010
Filter record from a file

Reposting since I didnt not get any reply.

I have a problem while filtering records from a file. Can somebody help please?

For eg: Consider the below files
Record file:
Code:
0003@00000000000190@20100401@201004012010040120100401@003@
0003@00000000000200@20100329@201003292010032920100329@003@
0003@00000000000550@20100401@201004012010040120100401@048@
0003@00000000000910@20100401@201004012010040120100401@017@
0004@00000000001401@20100328@201003282010032820100328@300@
0004@00000000001401@20100401@201004012010040120100401@010@
0004@00000000001431@20100401@201004012010040120100401@010@
0005@00000000001441@20100329@201003302010033020100330@300@
0005@00000000001830@20100328@201004012010040120100401@300@
0005@00000000002080@20100329@201003292010032920100329@003@

Filter File:
Code:
0004@300@20100328@20100329
0005@300@20100328@20100329

Code:
awk -F\@ 'NR==FNR{f[$1,$3,$5];next}($1SUBSEP$3SUBSEP$2 in f) {print $0}' $Record $Filter

This will not work since we are comparing 1st position to 1st, 3rd to 3rd and 5th to 2nd.

But if the filter file was like below this code would have worked.

Code:
 awk -F\@ 'NR==FNR{f[$1,$3,$5];next}($1SUBSEP$3SUBSEP$5 in f) {print $0}' $Record $Filter

Code:
0004@300@20100328@20100329@300
0005@300@20100328@20100329@300

Could somebody help me to figure out how we can make the first process work?
# 2  
Old 04-21-2010
How about:
Code:
awk -F\@ 'NR==FNR{f[$1,$2,$3];next} $1SUBSEP$5SUBSEP$3 in f' $Filter $Record

Code:
0004@00000000001401@20100328@201003282010032820100328@300@
0005@00000000001830@20100328@201004012010040120100401@300@

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CSV File:Filter duplicate records from column1 & another column having unique record

Hi Experts, I have csv file with 30, 40 columns Pasting just 2 column for problem description. Need to print error if below combination is not present in file check for column-1 (DocumentNumber) and filter columns where value in DocumentNumber field is same. For all such rows, the field... (7 Replies)
Discussion started by: as7951
7 Replies

2. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

3. UNIX for Dummies Questions & Answers

Filter records in a huge text file from a filter text file

Hi Folks, I have a text file with lots of rows with duplicates in the first column, i want to filter out records based on filter columns in a different filter text file. bash scripting is what i need. Data.txt Name OrderID Quantity Sam 123 300 Jay 342 498 Kev 78 2500 Sam 420 50 Vic 10... (3 Replies)
Discussion started by: tech_frk
3 Replies

4. Shell Programming and Scripting

Delete record filter by column

Dear friend, I have a file 2 files with column wise FILE_A ------------------------------ x,1,@ y,3,$ x,5,% FILE_B -------------------- x,1,@ i like to delete the all lines in FILE_A ,if first column available in FILE_B. output (in FILE_A) y,3,$ x,5,% (10 Replies)
Discussion started by: Jewel
10 Replies

5. Shell Programming and Scripting

awk-filter record by another file

I have file1 3049 3138 4672 22631 45324 112382 121240 125470 130289 186128 193996 194002 202776 228002 253221 273523 284601 284605 641858 (8 Replies)
Discussion started by: biomed
8 Replies

6. Shell Programming and Scripting

filter record from a file reading another file

Hi, I want to filter record from a file if the records in the second column matches the data in another file. I tried the below awk command but it filters the records in the filter file. I want the opposite, to include only the records in the filter file. I tried this: awk -F'|'... (8 Replies)
Discussion started by: gpaulose
8 Replies

7. Shell Programming and Scripting

Help in writing a KSH script to filter the latest record?

Hi All, I have a text file with the folowing content. BANGALORE|1417|2010-02-04 08:41:04.174|dob|xxx BANGALORE|1416|2010-02-04 08:23:19.566|dob|yyy BANGALORE|1415|2010-02-04 08:20:14.497|dob|aaa BANGALORE|1414|2010-02-04 08:19:40.065|dob|vvv BANGALORE|1413|2010-02-04... (4 Replies)
Discussion started by: Karpak
4 Replies

8. Shell Programming and Scripting

filter the uniq record problem

Anyone can help for filter the uniq record for below example? Thank you very much Input file 20090503011111|test|abc 20090503011112|tet1|abc|def 20090503011112|test1|bcd|def 20090503011131|abc|abc 20090503011131|bbc|bcd 20090503011152|bcd|abc 20090503011151|abc|abc... (8 Replies)
Discussion started by: bleach8578
8 Replies

9. UNIX for Dummies Questions & Answers

how to read record by record from a file in unix

Hi guys, i have a big file with the following format.This includes header(H),detail(D) and trailer(T) information in the file.My problem is i have to search for the character "6h" at 14 th and 15 th position in all the records .if it is there i have to write all those records into a... (1 Reply)
Discussion started by: raoscb
1 Replies

10. Shell Programming and Scripting

splitting a record and adding a record to a file

Hi, I am new to UNIX scripting and woiuld appreicate your help... Input file contains only one (but long) record: aaaaabbbbbcccccddddd..... Desired file: NEW RECORD #new record (hardcoded) added as first record - its length is irrelevant# aaaaa bbbbb ccccc ddddd ... ... ... (1 Reply)
Discussion started by: rsolap
1 Replies
Login or Register to Ask a Question