Remove line of text from multiple files in Linux

前端 未结 5 1479
时光取名叫无心
时光取名叫无心 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:20

    perl -ni -e 'print if not /mystring/' *
    

    This tells perl to loop over your file (-n), edit in place (-i), and print the line if it does not match your regular expression.

    Somewhat related, here's a handy way to perform a substitution over several files.

    perl -pi -e 's/something/other/' *
    

提交回复
热议问题