I am trying to write a shell script to simulate the following problem:
File A contains some entries like
JavaScript
x
a
b
c
and File B contains
JavaScript
a
g
d
t
q
c
the final file should have
(contents of file b which are not there in file a)
JavaScript
g
d
t
q
I was trying something like this but it’s not working:
JavaScript
for i in `cat b` ; do if[ (grep $i a) != $i ] then echo $i; done
Advertisement
Answer
You code has some errors:
forgot the closure of if statement : fi
“grep $i a” must be interpreted as a command , such as $(grep $i a) or `grep $i a`
You must add some characters around $(grep $i a) avoid empty string comparasion , such as “:” or something else, whatever.
Solution:
JavaScript
for i in `cat b` ; do if [ :$(grep $i a) != :$i ] ;then echo $i;fi; done