Cut files from 1 files and grep -v from another files

Viewed 37
File1
Ada
Billy
Charles
Delta
Eight
File2
Ada,User,xxx
Beba,User,xxx
Charles,Admin,xxx

I am exuting the following

Acc=`cut -d',' -f1 $PATH/File2
for account in `cat $File1 |grep -v Acc`
do
cat......
sed....

How to correct this?>

Expect output

Check file2 account existing on file1

Ada
Charles
2 Answers

This awk should work for you:

awk -F, 'FNR == NR {seen[$1]; next} $1 in seen' file2 file1

Ada
Charles

If this is not the output you're looking for then edit your question and add your expected output.

Your grep command searches for files which do not contain the string Acc. You need the Flag -f, which causes grep to accept a list of pattern from a file, something like this:

tmpf=/tmp/$$
cut -d',' -f1 File2 >$tmpf
for account in $(grep -f "$tmpf" File1)
do
  ...
done
Related