Remove line of text from multiple files in Linux

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

    To find a pattern and remove the line containing the pattern below command can be used

    find . -name "*" -type f | xargs sed -i -e '//d'
    

    Example : if you want to remove the line containing word sleep in all the xml files

    find . -name "*.xml" -type f | xargs sed -i -e '/sleep/d'
    

    NOTE : Be careful before choosing a pattern as it will delete the line recursively in all the files in the current directory hierarchy :)

提交回复
热议问题