Hello Friends,
I have
File1.txt has 300,000 records
File2.txt has 90,000 records
I need to verify that all 90,000 records are exist in File1.txt.
I have following query but it takes for ever.
cat File2.txt|while read line; do cat /tmp/File1.txt|grep $line >> res.tmp; done
Any better suggestion please?
Thanks,
Prashant
How about?:
while read line; do fgrep "$line" File1.txt >> res.tmp; done < File2.txt
See if this works. This gives the missing records in file1.
diff file1 file2 | grep '>' | sed 's/^.//'
egrep -v -f file1 file2 > temp
if [ $? -eq 0 ];then
echo "missed content"
cat temp
else
echo "all exist"
fi
rm temp
Friends,
If I have file1 with ONE column and file2 has TWO columns.
I need to print the entire line from file2 where file1 column matches.
File1
ABC
123
678
File2
QWE,ABC
DFR,123
D34,678
PP3,888
Thanks,
Prashant
With awk (nawk in Solaris), we can take advantage of NR and FNR (see man page) to store the mapping for file1 and check on the existence in the mapping for file2
awk -F"," '
NR==FNR {
f1[$1]=1
next
}
{
if ($2 in f1) {
print $1
}
}' file1 file2