Compare lines between two files

I have two files
I need to compare these two files and take the lines that are common in both the files and consider the line present in second file for my further processing
I have used "Awk" along with "FNR and NR" but that is not working

      gawk -F= '
>     FNR==NR {a[NR]=$1; next};
>     {b[$1]=$0}
>     END{for (i in a) if (a in b) print b[a]}
> ' executed.txt org_sysctl.txt  

The two files are

root@39da864625c7:/home# cat executed.txt
d.cdrom.124=1
d.cdrom.12=0
d.cdrom.122=0
d.cdrom.34=0
d.cdrom.lo=0

root@39da864625c7:/home# cat org_sysctl.txt
d.cdrom.124 = 1
d.cdrom.12 = 600
d.cdrom.122 = 400
d.cdrom.34 = 200
d.cdrom.lo = 100
v.pet = 0
v.static = 1
v.swappy = 60
v.user = 124270
v.vfs = 100
v.done = 0

I want the output as the following

d.cdrom.124 = 1
d.cdrom.12 = 600
d.cdrom.122 = 400
d.cdrom.34 = 200
d.cdrom.lo = 100

Please help :confused:

Hello Priya Amaresh,

Could you please try following and let me know if this helps you.

awk 'FNR==NR{A[$1];next} ($1 in A){print $0}' FS="=" executed.txt FS=" = " org_sysctl.txt

Output will be as follows.

d.cdrom.124 = 1
d.cdrom.12 = 600
d.cdrom.122 = 400
d.cdrom.34 = 200
d.cdrom.lo = 100
 

Thanks,
R. Singh

1 Like

WHAT did not work?

From just looking at the sample files you can see that there won't be any immediate match without some preprocessing...