awk script problem

April 3, 2009 at 14:04:57
Specs: linux
I am new to awk, can somone please correct the following script

awk -F "," 'BEGIN {
foreach ((getline < "file1.csv") > 0)
{i++
a[i]=1 --> assuming the first column in the row will be stored in a[]
foreach (a[i] in f1) {
if (a[i] == $5) continue
print a[i];
}
}
} file2.csv'

Here is what I want to do

File 1
laeg.com,2/2/23,a,b,ga
aeg.com,2/2/23,a,b,ga
xyz.com,2/2/12,a,b,c
eg.com,2/2/23,a,b,ga

File 2
1,2,ua,xyz.com
1,2,ua,abc.com
1,2,ua,eg.com
1,2,ua,easg.com
1,2,ua,zth.com

File 3
laeg.com,2/2/23,a,b,ga
aeg.com,2/2/23,a,b,ga

while reading in file1 it should compare in each row on file2 if found any where in the file2 it should be ignored while writing into output file.


See More: awk script problem

Report •


#1
April 3, 2009 at 19:46:00
awk -F, 'FNR==NR{ _[$4]=$0;next}(!($1 in _))' file2 file1

Unix Win32 tools | Gawk for Windows


Report •

#2
April 6, 2009 at 08:42:52
Both the files has different number of records. Sorry I could have told you first. File 1 has 80K and file2 has 2million records.

Report •

Related Solutions


Ask Question