Search

script to delete the lines from a file having patterns present in another file

Let us assume we have set of patterns in a file as shown below.

data1:



And a file with the contents

data2:



If we want to search for the patterns in the file data1 and delete the lines that have the pattern in the file data2, we can do it using the following script.

del_pattern.sh :



save it in the same directory where the above two text files are saved,give it execute permission and execute it.



The while loop, loops through the file data1, reading on line at a time. The sed command in the while loop searches for the pattern in the file data2 and any line that has the pattern will be substituted by a blank line.

Instead of replacing with a blank line, we can delete the line using the following script.

del_pattern.sh



save it in the same directory where the above two text files are saved,give it execute permission and execute it.




1 comment:

  1. Do you come across unexpected issues while sending digital currency to another wallet in Binance? For the smooth and hassle-free sending of digital currency, you should contact the experts who can explain the complete process of sending the currency in a detailed manner so that you can cut the errors that are unwanted and face no hurdles.Just dial Binance support phone number and speak to the team for advantageous assistance and support.

    ReplyDelete