comparing 2 files in shell script

I have 2 files
config1h.txt
-----------------

BFMU=ENABLE,ID=PM
THR=OFF,REP=ALL,CON=IACM,TIM=OFF;GPON collection strategy
1.3.6.1.2.1.2.2:8
1.3.6.1.2.1.2.2:7
1.3.6.1.4.1.637.61.1.35.11.4:4
1.3.6.1.4.1.637.61.1.35.11.4:3
1.3.6.1.4.1.637.61.1.35.10.1:2
1.3.6.1.4.1.637.61.1.35.10.1:43
1.3.6.1.4.1.637.61.1.35.10.1:4
1.3.6.1.4.1.637.61.1.35.10.1:5
1.3.6.1.4.1.637.61.1.35.10.1:20
1.3.6.1.4.1.637.61.1.35.10.1:26
1.3.6.1.4.1.637.61.1.35.11.2:4
1.3.6.1.4.1.637.61.1.35.11.2:14
1.3.6.1.4.1.637.61.1.35.11.2:19
1.3.6.1.4.1.637.61.1.35.11.2:15
1.3.6.1.4.1.637.61.1.35.11.2:13
1.3.6.1.4.1.637.61.1.35.11.2:12
1.3.6.1.4.1.637.61.1.35.10.14:3
1.3.6.1.4.1.637.61.1.35.10.14:5
1.3.6.1.4.1.637.61.1.35.10.14:2
1.3.6.1.4.1.637.61.1.35.10.14:4
1.3.6.1.4.1.637.61.1.35.10.14:6
1.3.6.1.4.1.637.61.1.35.10.18:2
1.3.6.1.4.1.637.61.1.35.10.19:1
1.3.6.1.4.1.637.61.1.35.10.19:12
1.3.6.1.4.1.637.61.1.35.10.19:11
1.3.6.1.4.1.637.61.1.35.10.19:13
1.3.6.1.4.1.637.61.1.35.10.19:10
1.3.6.1.4.1.637.61.1.35.10.4:3
1.3.6.1.4.1.637.61.1.35.10.4:2
1.3.6.1.4.1.637.61.1.35.15.3:3
1.3.6.1.4.1.637.61.1.35.15.3:4
1.3.6.1.4.1.637.61.1.23.3:8
1.3.6.1.4.1.637.61.1.23.3:3
1.3.6.1.4.1.637.61.1.23.3:6
1.3.6.1.4.1.637.61.1.23.3:5
0

PM09134500
--------------------

BFMU Version: V1 
START TIME: 17/05/11 08:00:30.000000
1.3.6.1.2.1.2.2
.1:8.285306880=1
.1:8.285306881=1
.1:8.285306882=1
.1:8.285306883=1
.1:8.285306884=1
.1:8.285306885=1
.1:8.285736960=1
.1:8.285736961=1
.1:8.286064640=2
.1:8.286064641=2
.1:8.286064642=2
.1:8.286064643=2
1.3.6.1.2.1.2.2
.1:7.285306880=1
.1:7.285306881=1
.1:7.285306882=1
.1:7.285306883=1
.1:7.285306884=1
.1:7.285306885=1
.1:7.285736960=1
.1:7.285736961=1
.1:7.286064640=2
.1:7.286064641=2
.1:7.286064642=2
.1:7.286064643=2
1.3.6.1.4.1.637.61.1.35.11.4
.1:4.285736960.1=0
.1:4.285736960.2=0
.1:4.285736960.3=0
.1:4.285736960.4=0
.1:4.285736960.5=0
.1:4.285736960.6=0
.1:4.285736960.7=0
.1:4.285736960.8=0
.1:4.285736960.9=0
.1:4.285736960.10=0
.1:4.285736960.11=0
.1:4.285736960.12=0
.1:4.285736960.13=0
.1:4.285736960.14=0
.1:4.285736960.15=0
.1:4.285736960.16=0
.1:4.285736960.17=0
.1:4.285736960.18=0
.1:4.285736960.19=0
.1:4.285736960.20=0
.1:4.285736960.21=0
.1:4.285736960.22=0
.1:4.285736960.23=0
.1:4.285736960.24=0
.1:4.285736960.25=0
.1:4.285736960.26=0
.1:4.285736960.27=0
.1:4.285736960.28=0
.1:4.285736960.29=0
.1:4.285736960.30=0
.1:4.285736960.31=0
.1:4.285736960.32=0
.1:4.285736960.33=0
.1:4.285736960.34=0
.1:4.285736960.35=0
.1:4.285736960.36=0
.1:4.285736960.37=0
.1:4.285736960.38=0
.1:4.285736960.39=0
.1:4.285736960.40=0
.1:4.285736960.41=0
.1:4.285736960.42=0
.1:4.285736960.43=0
.1:4.285736960.44=0
.1:4.285736960.45=0
.1:4.285736960.46=0
.1:4.285736960.47=0
.1:4.285736960.48=0
.1:4.285736960.49=0
.1:4.285736960.50=0
.1:4.285736960.51=0
.1:4.285736960.52=0
.1:4.285736960.53=0
.1:4.285736960.54=0
.1:4.285736960.55=0
.1:4.285736960.56=0
.1:4.285736960.57=0
.1:4.285736960.58=0
.1:4.285736960.59=0
.1:4.285736960.60=0
.1:4.285736960.61=0
.1:4.285736960.62=0
.1:4.285736960.63=0
.1:4.285736960.64=0
.1:4.285736961.1=0
.1:4.285736961.2=0
.1:4.285736961.3=0
.1:4.285736961.4=0
.1:4.285736961.5=0
.1:4.285736961.6=0
.1:4.285736961.7=0
.1:4.285736961.8=0
.1:4.285736961.9=0
.1:4.285736961.10=0
.1:4.285736961.11=0
.1:4.285736961.12=0
.1:4.285736961.13=0
.1:4.285736961.14=0
.1:4.285736961.15=0
.1:4.285736961.16=0
.1:4.285736961.17=0
.1:4.285736961.18=0
.1:4.285736961.19=0
.1:4.285736961.20=0
.1:4.285736961.21=0
.1:4.285736961.22=0
.1:4.285736961.23=0
.1:4.285736961.24=0
.1:4.285736961.25=0
.1:4.285736961.26=0
.1:4.285736961.27=0
.1:4.285736961.28=0
.1:4.285736961.29=0
.1:4.285736961.30=0
.1:4.285736961.31=0
.1:4.285736961.32=0
.1:4.285736961.33=0
.1:4.285736961.34=0
.1:4.285736961.35=0
.1:4.285736961.36=0
.1:4.285736961.37=0
.1:4.285736961.38=0
.1:4.285736961.39=0
.1:4.285736961.40=0
.1:4.285736961.41=0
.1:4.285736961.42=0
.1:4.285736961.43=0
.1:4.285736961.44=0
.1:4.285736961.45=0
.1:4.285736961.46=0
.1:4.285736961.47=0
.1:4.285736961.48=0
.1:4.285736961.49=0
.1:4.285736961.50=0
.1:4.285736961.51=0
.1:4.285736961.52=0
.1:4.285736961.53=0
.1:4.285736961.54=0
.1:4.285736961.55=0
.1:4.285736961.56=0
.1:4.285736961.57=0
.1:4.285736961.58=0
.1:4.285736961.59=0
.1:4.285736961.60=0
.1:4.285736961.61=0
.1:4.285736961.62=0
.1:4.285736961.63=0
.1:4.285736961.64=0
.1:4.286064640.1=0
.1:4.286064640.2=0
.1:4.286064640.3=0
.1:4.286064640.4=0
.1:4.286064640.5=0
.1:4.286064640.6=0
.1:4.286064640.7=0
.1:4.286064640.8=0
.1:4.286064640.9=0
.1:4.286064640.10=0
.1:4.286064640.11=0
.1:4.286064640.12=0
.1:4.286064640.13=0
.1:4.286064640.14=0
.1:4.286064640.15=0
.1:4.286064640.16=0
.1:4.286064640.17=0
.1:4.286064640.18=0
.1:4.286064640.19=0
.1:4.286064640.20=0
.1:4.286064640.21=0
.1:4.286064640.22=0
.1:4.286064640.23=0
.1:4.286064640.24=0
.1:4.286064640.25=0
.1:4.286064640.26=0
.1:4.286064640.27=0
.1:4.286064640.28=0
.1:4.286064640.29=0
.1:4.286064640.30=0
.1:4.286064640.31=0
.1:4.286064640.32=0
.1:4.286064640.33=0
.1:4.286064640.34=0
.1:4.286064640.35=0
.1:4.286064640.36=0
.1:4.286064640.37=0
.1:4.286064640.38=0
.1:4.286064640.39=0
.1:4.286064640.40=0
.1:4.286064640.41=0
.1:4.286064640.42=0
.1:4.286064640.43=0
.1:4.286064640.44=0
.1:4.286064640.45=0
.1:4.286064640.46=0
.1:4.286064640.47=0
.1:4.286064640.48=0
.1:4.286064640.49=0
.1:4.286064640.50=0
.1:4.286064640.51=0
.1:4.286064640.52=0
.1:4.286064640.53=0
.1:4.286064640.54=0
.1:4.286064640.55=0
.1:4.286064640.56=0
.1:4.286064640.57=0
.1:4.286064640.58=0
.1:4.286064640.59=0
.1:4.286064640.60=0
.1:4.286064640.61=0
.1:4.286064640.62=0
.1:4.286064640.63=0
.1:4.286064640.64=0
.1:4.286064641.1=0
.1:4.286064641.2=0
.1:4.286064641.3=0
.1:4.286064641.4=0
.1:4.286064641.5=0
.1:4.286064641.6=0
.1:4.286064641.7=0
.1:4.286064641.8=0
.1:4.286064641.9=0
.1:4.286064641.10=0
.1:4.286064641.11=0
.1:4.286064641.12=0
.1:4.286064641.13=0
.1:4.286064641.14=0
.1:4.286064641.15=0
.1:4.286064641.16=0
.1:4.286064641.17=0
.1:4.286064641.18=0
.1:4.286064641.19=0
.1:4.286064641.20=0
.1:4.286064641.21=0
.1:4.286064641.22=0
.1:4.286064641.23=0
.1:4.286064641.24=0
.1:4.286064641.25=0
.1:4.286064641.26=0
.1:4.286064641.27=0
.1:4.286064641.28=0
.1:4.286064641.29=0
.1:4.286064641.30=0
.1:4.286064641.31=0
.1:4.286064641.32=0
.1:4.286064641.33=0
.1:4.286064641.34=0
.1:4.286064641.35=0
.1:4.286064641.36=0
.1:4.286064641.37=0
.1:4.286064641.38=0
.1:4.286064641.39=0
.1:4.286064641.40=0
.1:4.286064641.41=0
.1:4.286064641.42=0
.1:4.286064641.43=0
.1:4.286064641.44=0
.1:4.286064641.45=0
.1:4.286064641.46=0
.1:4.286064641.47=0
.1:4.286064641.48=0
.1:4.286064641.49=0
.1:4.286064641.50=0
.1:4.286064641.51=0
.1:4.286064641.52=0
.1:4.286064641.53=0
.1:4.286064641.54=0
.1:4.286064641.55=0
.1:4.286064641.56=0
.1:4.286064641.57=0
.1:4.286064641.58=0
.1:4.286064641.59=0
.1:4.286064641.60=0
.1:4.286064641.61=0
.1:4.286064641.62=0
.1:4.286064641.63=0
.1:4.286064641.64=0
.1:4.286064642.1=0
.1:4.286064642.2=0
.1:4.286064642.3=0
.1:4.286064642.4=0
.1:4.286064642.5=0
.1:4.286064642.6=0
.1:4.286064642.7=0
.1:4.286064642.8=0
.1:4.286064642.9=0
.1:4.286064642.10=0
.1:4.286064642.11=0
.1:4.286064642.12=0
.1:4.286064642.13=0
.1:4.286064642.14=0
.1:4.286064642.15=0
.1:4.286064642.16=0
.1:4.286064642.17=0
.1:4.286064642.18=0
.1:4.286064642.19=0
.1:4.286064642.20=0
.1:4.286064642.21=0
.1:4.286064642.22=0
.1:4.286064642.23=0
.1:4.286064642.24=0
.1:4.286064642.25=0
.1:4.286064642.26=0
.1:4.286064642.27=0
.1:4.286064642.28=0
.1:4.286064642.29=0
.1:4.286064642.30=0
.1:4.286064642.31=0
.1:4.286064642.32=0
.1:4.286064642.33=0
.1:4.286064642.34=0
.1:4.286064642.35=0
.1:4.286064642.36=0
.1:4.286064642.37=0
.1:4.286064642.38=0
.1:4.286064642.39=0
.1:4.286064642.40=0
.1:4.286064642.41=0
.1:4.286064642.42=0
.1:4.286064642.43=0
.1:4.286064642.44=0
.1:4.286064642.45=0
.1:4.286064642.46=0
.1:4.286064642.47=0
.1:4.286064642.48=0
.1:4.286064642.49=0
.1:4.286064642.50=0
.1:4.286064642.51=0
.1:4.286064642.52=0
.1:4.286064642.53=0
.1:4.286064642.54=0
.1:4.286064642.55=0
.1:4.286064642.56=0
.1:4.286064642.57=0
.1:4.286064642.58=0
.1:4.286064642.59=0
.1:4.286064642.60=0
.1:4.286064642.61=0
.1:4.286064642.62=0
.1:4.286064642.63=0
.1:4.286064642.64=0
.1:4.286064643.1=0
.1:4.286064643.2=0
.1:4.286064643.3=0
.1:4.286064643.4=0
.1:4.286064643.5=0
.1:4.286064643.6=0
.1:4.286064643.7=0
.1:4.286064643.8=0
.1:4.286064643.9=0
.1:4.286064643.10=0
.1:4.286064643.11=0
.1:4.286064643.12=0
.1:4.286064643.13=0
.1:4.286064643.14=0
.1:4.286064643.15=0
.1:4.286064643.16=0
.1:4.286064643.17=0
.1:4.286064643.18=0
.1:4.286064643.19=0
.1:4.286064643.20=0
.1:4.286064643.21=0
.1:4.286064643.22=0
.1:4.286064643.23=0
.1:4.286064643.24=0
.1:4.286064643.25=0
.1:4.286064643.26=0
.1:4.286064643.27=0
.1:4.286064643.28=0
.1:4.286064643.29=0
.1:4.286064643.30=0
.1:4.286064643.31=0
.1:4.286064643.32=0
.1:4.286064643.33=0
.1:4.286064643.34=0
.1:4.286064643.35=0
.1:4.286064643.36=0
.1:4.286064643.37=0
.1:4.286064643.38=0
.1:4.286064643.39=0
.1:4.286064643.40=0
.1:4.286064643.41=0
.1:4.286064643.42=0
.1:4.286064643.43=0
.1:4.286064643.44=0
.1:4.286064643.45=0
.1:4.286064643.46=0
.1:4.286064643.47=0
.1:4.286064643.48=0
.1:4.286064643.49=0
.1:4.286064643.50=0
.1:4.286064643.51=0
.1:4.286064643.52=0
.1:4.286064643.53=0
.1:4.286064643.54=0
.1:4.286064643.55=0
.1:4.286064643.56=0
.1:4.286064643.57=0
.1:4.286064643.58=0
.1:4.286064643.59=0
.1:4.286064643.60=0
.1:4.286064643.61=0
.1:4.286064643.62=0
.1:4.286064643.63=0
.1:4.286064643.64=0
1.3.6.1.4.1.637.61.1.35.11.4
.1:3.285736960.1=9
.1:3.285736960.2=26
.1:3.285736960.3=7
.1:3.285736960.4=10
.1:3.285736960.5=0
.1:3.285736960.6=0
.1:3.285736960.7=0
.1:3.285736960.8=0
.1:3.285736960.9=0
.1:3.285736960.10=0
.1:3.285736960.11=0
.1:3.285736960.12=0

Now i need to compare 2 files and give the output
the strategy here is that all the config entries should be compared with pmfile
The one in config file

1.3.6.1.2.1.2.2:8 

pmfile

1.3.6.1.2.1.2.2
.1:8.285306880=1

this means that "1.3.6.1.2.1.2.2" is covered in pmfile and ":8"in config file is represented as ".1:8" in pmfile .Like wise the others

Now my shell script output should be

1.3.6.1.2.1.2.2:8    TRUE
1.3.6.1.2.1.2.2:7    TRUE
1.3.6.1.4.1.637.61.1.35.11.4:4    TRUE
1.3.6.1.4.1.637.61.1.35.11.4:3    TRUE
1.3.6.1.4.1.637.61.1.35.10.1:2    FALSE
1.3.6.1.4.1.637.61.1.35.10.1:43    FALSE
1.3.6.1.4.1.637.61.1.35.10.1:4    FALSE

.
.
.

Certainly a large data sample :wink:

for i in $(grep \: config1h.txt |cut -d \: -f1); do 
   if FOUND=$(grep $i PM09134500) ; then 
      echo "$i TRUE"
   else 
      echo "$i FALSE"
   fi
done

Thank u soooo much.
I was sitting in this for many days. U made it simple ans easy. :slight_smile:

# awk -F. 'NR==FNR{if(/^1/){f=$0;next};if(/^./){a[f substr($2,2)];next}}{if(/^[0-9]/)print $0,(a[$0])?"TRUE":"FALSE"}' PM09134500 config1h.txt
1.3.6.1.2.1.2.2:8 TRUE
1.3.6.1.2.1.2.2:7 TRUE
1.3.6.1.4.1.637.61.1.35.11.4:4 TRUE
1.3.6.1.4.1.637.61.1.35.11.4:3 TRUE
1.3.6.1.4.1.637.61.1.35.10.1:2 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:43 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:4 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:5 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:20 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:26 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:4 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:14 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:19 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:15 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:13 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:12 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:3 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:5 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:2 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:4 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:6 FALSE
1.3.6.1.4.1.637.61.1.35.10.18:2 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:1 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:12 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:11 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:13 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:10 FALSE
1.3.6.1.4.1.637.61.1.35.10.4:3 FALSE
1.3.6.1.4.1.637.61.1.35.10.4:2 FALSE
1.3.6.1.4.1.637.61.1.35.15.3:3 FALSE
1.3.6.1.4.1.637.61.1.35.15.3:4 FALSE
1.3.6.1.4.1.637.61.1.23.3:8 FALSE
1.3.6.1.4.1.637.61.1.23.3:3 FALSE
1.3.6.1.4.1.637.61.1.23.3:6 FALSE
1.3.6.1.4.1.637.61.1.23.3:5 FALSE
0 FALSE

Skrynesaver check your output

1 Like

Ooops, good catch, I dropped the suffix in the cut.

This dint work for me. :frowning:
What is that im missing here???

# nawk -F. 'NR==FNR{if(/^1/){f=$0;next};if(/^./){a[f substr($2,2)];next}}{if(/^[0-9]/)print $0,(a[$0])?"TRUE":"FALSE"}' PM00 config.txt
1.3.6.1.2.1.2.2:7 FALSE
1.3.6.1.2.1.2.2:8 FALSE
1.3.6.1.4.1.637.61.1.35.11.4:4 FALSE
1.3.6.1.4.1.637.61.1.35.11.4:3 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:2 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:43 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:4 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:26 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:20 FALSE
1.3.6.1.4.1.637.61.1.35.10.1:5 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:4 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:13 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:15 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:14 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:12 FALSE
1.3.6.1.4.1.637.61.1.35.11.2:19 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:2 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:4 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:3 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:5 FALSE
1.3.6.1.4.1.637.61.1.35.10.14:6 FALSE
1.3.6.1.4.1.637.61.1.35.10.18:2 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:1 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:11 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:13 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:12 FALSE
1.3.6.1.4.1.637.61.1.35.10.19:10 FALSE
1.3.6.1.4.1.637.61.1.35.10.4:2 FALSE
1.3.6.1.4.1.637.61.1.35.10.4:3 FALSE
1.3.6.1.4.1.637.61.1.35.15.3:3 FALSE
1.3.6.1.4.1.637.61.1.35.15.3:4 FALSE
1.3.6.1.4.1.637.61.1.23.3:8 FALSE
1.3.6.1.4.1.637.61.1.23.3:6 FALSE
1.3.6.1.4.1.637.61.1.23.3:5 FALSE
1.3.6.1.4.1.637.61.1.23.3:3 FALSE
0 FALSE

Im using bash shell in solaris

Amending my previous script so as to preserve the suffix you get:

for i in $(grep \: config1h.txt ); do
     j=$(echo $i | cut -d \: -f1) # remove the suffix in the loop
     if FOUND=$(grep $j PM09134500) ; then
        echo "$i TRUE"
    else
        echo "$i FALSE"
    fi
done

Solaris provides a POSIX compliant awk implementation installed in the /usr/xpg4/bin directory.