Passing file content as parameter

Hi All,

I am passing a file value as parameter to awk command;
Par.txt

A|B

Input.txt

A,1
B,3
C,4
D,5

My desired output should be

A,1
B,3

I have tried the below code but no output redirected:

awk '/echo $(<Par.txt)/' Input.txt

Please adivse me if some thing wrong in this command.

Thanks

bash-3.2$ tr "\|" "\n" < Par.txt > newPar.txt
bash-3.2$ fgrep -f newPar.txt Input.txt
A,1
B,3

Hi,

Try this one,

awk -v Fld="A|B" 'BEGIN{FS=",";split(Fld,a,"|");}{for(i in a){if(a == $1){print $0;}}}' file

Cheers,
Ranga:)

$ nawk -v p=$(cat Par.txt) '$0~p' Input.txt
A,1
B,3

if you want to compare in first column then use $1~p

2 Likes

Thanks working fine.....