![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Based on num of records in file1 need to check records in file2 to set some condns | mavesum | Shell Programming and Scripting | 3 | 11-26-2008 10:48 AM |
| Using a variable to select records with awk | joeyg | Shell Programming and Scripting | 5 | 09-26-2008 11:48 AM |
| Script needed to select and delete lower case and mixed case records | abhilash mn | Shell Programming and Scripting | 1 | 03-17-2008 08:00 AM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 01:15 PM |
| Select records based on search criteria on first column | shashi_kiran_v | UNIX for Dummies Questions & Answers | 2 | 12-02-2005 01:49 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
select records from one file based on a second file
Hi all: I have two files: file1: Code:
74 DS 9871 199009871 1 1990 4 1 165200 Sc
pr de te sa ox
1.0 1.0 13.0000 35.7560 5.950
3.0 3.0 13.0100 35.7550 5.970
**
74 DS 99004 74DS99004 6738 1990 4 1 165200 Eb
pr de te sa ox
1.0 1.0 13.0000 35.7560 5.950
3.0 3.0 13.0100 35.7550 5.970
**
29 CS 563 198700563 280 1987 7 27 043900 Ic
pr de te sa ox
9.0 8.9 12.2700 35.6500 6.060
11.0 10.9 12.2100 35.6490 6.100
**
74 DS 9871 199009871 8 1990 4 3 161500 Sc
pr de te sa ox
1.0 1.0 13.4500 35.7420 5.940
3.0 3.0 13.4500 35.7420 5.950
**
74 DS 99004 74DS99004 6911 1990 4 6 042500 Eb
pr de te sa
2.0 2.0 15.3300 35.5920
3.0 3.0 15.3300 35.5920
**
and file2: Code:
29 CS 563 198700563 280 1987 7 27 043900 Ic 74 DS 99004 74DS99004 6738 1990 4 1 165200 Eb 74 DS 99004 74DS99004 6911 1990 4 6 042500 Eb What I need is to retain from file1 the full records pointed in file 2 (not need to be ordered) in such as: Code:
74 DS 99004 74DS99004 6738 1990 4 1 165200 Eb
pr de te sa ox
1.0 1.0 13.0000 35.7560 5.950
3.0 3.0 13.0100 35.7550 5.970
**
29 CS 563 198700563 280 1987 7 27 043900 Ic
pr de te sa ox
9.0 8.9 12.2700 35.6500 6.060
11.0 10.9 12.2100 35.6490 6.100
**
74 DS 99004 74DS99004 6911 1990 4 6 042500 Eb
pr de te sa
2.0 2.0 15.3300 35.5920
3.0 3.0 15.3300 35.5920
**
I have tried several approaches with awk oneliners, but didn't succeed because don't know how to deal with multiple files each with dissimilar ORS and FS. That is for file1 RS and ORS are the awk defaults whereas for file2: Code:
{RS="\\*\\*\n+";ORS="**\n"}.
Do you have a clue on how to proceed? Thanks, r.- Last edited by rleal; 07-17-2009 at 05:42 AM.. Reason: bad post title |
|
||||
|
Hi Rakesh, Code:
FNR==NR{a[$0]=$0;next}
is used for storing the first file (here file2) content into an array "a" based on the key "$0" ( which is a complete row). Code:
($0 in a),$0=="**"' The above code is verifying whether each row from the file1 is present in the array or not ?.if present print it till the row equals to "**". Ygor: Please let me know if i am wrong somewhere. |
|
||||
|
And this is because FNR is reset for each file read...right?
|
|
||||
|
Quote:
Sorry i forgot to mention .Yes. "NR" will be keep on incrementing where as "FNR" will reset once a file processing is over and re start again for the next file. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|