Compare 2 files and remove any lines in file2 when they match values found in file1

前端 未结 4 676
死守一世寂寞
死守一世寂寞 2020-12-10 22:11

I have two files. i am trying to remove any lines in file2 when they match values found in file1. One file has a listing like so:

File1

ZNI008
ZNI009         


        
4条回答
  •  北海茫月
    2020-12-10 23:05

    This is admittedly ugly but it does work. However, the path must be the same for all of the (except of course the ZNI### portion). All but the ZNI### of the path is removed so the command grep -vf can run correctly on the sorted files.

    First Convert "testfile2" to "testfileconverted" to just show the ZNI###

    cat /testfile2 | sed 's:^.*_ZNI:ZNI:g' | sed 's:_.*::g' > /testfileconverted
    

    Second use inverse grep of the converted file compared to the "testfile1" and add the reformatted output to "testfile3"

    bash -c 'grep -vf <(sort /testfileconverted) <(sort /testfile1)' | sed "s:^:\copy /Y \\\|server\\\foldername\\\version\\\20050001_:g" | sed "s:$:_162635\.xml \\\|server\\\foldername\\\version\\\folder\\\:g" | sed "s:|:\\\:g" > /testfile3
    

提交回复
热议问题