Remove line of text from multiple files in Linux

前端 未结 5 1475
时光取名叫无心
时光取名叫无心 2020-12-08 04:07

Is there a simple way to remove the same line of text from a folder full of text documents at the command line?

5条回答
  •  执笔经年
    2020-12-08 04:19

    If your version of sed allows the -i.bak flag (edit in place):

    sed -i.bak '/line of text/d' * 
    

    If not, simply put it in a bash loop:

    for file in *.txt
    do
        sed '/line of text/d' "$file" > "$file".new_file.txt
    done
    

提交回复
热议问题