4

sed 使用笔记

 1 week ago
source link: https://deweyreed.github.io/2024/04/21/sed/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

sed 使用笔记

2024-04-21Notes

sed

https://regex-vis.com/

  • 替换oldfile文件中的每行第一个findreplace,保存内容到newfile

    sed 's/find/replace/' <oldfile >newfile

  • 替换oldfile文件中的每一个<space>findreplace,保存内容到newfile

    sed 's/ find/replace/g' <oldfile >newfile

  • 替换filename文件中的每一个findreplace

    sed -i 's/find/replace/g' filename

  • 替换filename文件中的包含Replace文字的每一行中的theTHE

    sed -i '/Replace/s/the/THE/g' filename

  • 删除filename文件中的包含Replace文字的每一行

    sed -i '/Replace/d' filename

  • 不使用-i则打印内容

  • 运行多条命令

    • sed -i '...;...' filename
    • sed -i -e '...' -e '...' filename
  • \/转义/或使用s#find#replace#g, s|find|replace|g, .

  • 打印出包含usr的每一行: sed '/user/p'

  • 删除redacted: sed "s/redacted//g filename

  • 删除空行: sed "/^$/d" filename


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK