bash – Remove Lines Containing Symbol or Empty Line Using sed

bashsedtext processing

How to delete from all .asc files in the directory the lines containing '=' and 'HISTORY' (which is always capitalized) and all empty lines?

I think it will be something like:

for file in /media/linux/DATADISK/*.asc
do
    sed '/=/d' 
    sed '/HISTORY/d' 
done

Best Answer

do all in one go.

sed -E '/=|HISTORY|^$/d' /media/linux/DATADISK/*.asc

Replace ^$ with ^[[:blank:]]*$ in addition to remove lines those containing only Tabs/Spaces too or use ^[[:blank:]]*\r?$ if your file's line-feed could be Windows-Style \r\n.

to update changes inplace, add -i option, see man sed for details.

Related Question