Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract data from two files and create another 2

Status
Not open for further replies.

pdtak

Technical User
Feb 25, 2008
63
US
I have two files that contains just file names.
The first files has the nfs mount points (ie. /mnt, /nfs1, etc.)
Second file has long file names (ie. /usr/bin/perl, /nfs1/file1, etc.)
I want the third file to contain only the non-nfs mounted files.

Example:

file1:
/mnt
/nfs1
/nfs2

file2:
/usr/bin/perl
/mnt/file1
/nfs1/file2
/etc/file3
/usr/bin/ls
/home/abc
/nfs2/file5

file3:
/usr/bin/perl
/etc/file3
/usr/bin/ls
/home/abc

Thanks in advance.
 
Code:
$> awk '!/mnt|nfs/ {print}' file1 file2 >> file3
$> cat file3
/usr/bin/perl
/etc/file3
/usr/bin/ls
/home/abc

laters
zaxxon
 
Hi

I think pdtak wants something like this :
Code:
awk 'FNR==NR{m[NR]=$0;next}{for(i in m)if($0~"^"m[i])next}1' file1 file2 > file3

[gray]# or[/gray]

awk -F / 'FNR==NR{m[$2]=1;next}!($2 in m)' file1 file2 > file3
Tested with [tt]gawk[/tt] and [tt]mawk[/tt].

Feherke.
 
Looking at it again yes, you're right. Something like grep -vf ... but with awk.

laters
zaxxon
 
Thank you both for your input.
I'll incorporate them into my script and see which works better.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top