krthk krthk - 7 months ago 19
Perl Question

Delete a line starting with particular String in all 3000 files

I want to delete a particular line in each of 3000 text files.

I have tried using Notepad Plus but it creates a blank line for each matching line.

Sample File Content:



SAMPLE TXT FILE
---------------------
phone number
address
IAM A DEFAULT
city
state
pincode
----------------


Here
IAM A DEFAULT
is present in all 3000 files and it is present only once

Answer

With GNU sed and GNU bash 4:

shopt -s globstar nullglob
sed -i '/^IAM A DEFAULT/d' **/*.txt