Issue
i am not familiar with bash script, after some research, i found some hints but still need your effort.
Given i have a resources.txt, contains
a
b
c
d
and a whitelist.txt file, contains
c
d
I would like to remove all items that exactly match from whitelist file to resource file. so the expected output is
a
b
Expect c and d is removed because they are in whitelist file.
I have created below script to read it, but don't know how to replace each one by one to resource file.
# read the whitelist file
echo whitelist.txt | awk '{for (i=1; i<=NF; i++) printf "%s\n",$i}
# replace item in resource file
awk '{sub(/c/,""); print}' resources.txt
Your help is greatly appreciated, thanks a lot!!
Solution
I would use this grep:
grep -Fvxf whitelist.txt resources.txt
-F
fixed/literal strings (no regex)-f FILE
get patterns from FILE-x
match the whole line-v
print lines which don't match- This grep is POSIX
Answered By - dan Answer Checked By - Mildred Charles (WPSolving Admin)