最近我碰到了grep命令:
- /usr/xpg4/bin/grep -Ff grep.txt input.txt > output.txt
这根据我的理解意味着从input.txt,grep grep.txt中包含的内容并将其输出到output.txt.
我想为sed做类似的事情,即我想将sed命令保存在一个单独的文件(例如sed.txt)中,并且要将它们应用于输入文件(例如input.txt)并创建输出文件(例如output.txt ).
我试过以下:
- /usr/xpg4/bin/sed -f sed.txt input.txt > output.txt
它不工作,我得到以下错误:
- sed: command garbled
sed.txt
- sed s/234/acn/ input.txt
- sed s/78gt/hit/ input.txt
input.txt中
- 234GH
- 5234BTW
- 89er
- 678tfg
- 234
- 234YT
- tfg456
- wert
- 78gt
- gh23444
请指教.
您的sed.txt应该只包含sed命令:没有前缀与sed或后缀与输入文件.在你的情况下,它应该是:
- # sed.txt
- s/234/acn/
- s/78gt/hit/
当你的输入:
- $/usr/xpg4/bin/sed -f sed.txt input.txt
- acnGH
- 5acnBTW
- 89er
- 678tfg
- acn
- acnYT
- tfg456
- wert
- hit
- ghacn44