Tuesday, July 2, 2013

bash file set operations

Given 2 files
keep.txt
BBB
CCC

all.txt
AAA
BBB
CCC
DDD
EEE
FFF
Leave entries that is not found in keep.txt file
output.txt
AAA
DDD
EEE
FFF
echo "">output.txt && while read line; do if [[ -z $(grep "${line}" keep.txt) ]] ; then echo ${line} >> output.txt; fi; done < all.txt

No comments:

Post a Comment