Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 shell 功能非常有限的 unix 系统上缩短日志文件。我首选的方法是使用ed.
ed
删除固定数量的行可以正常工作:
ed -s file.txt <<< $'1,4d\nwq'
但是如何扩展要从oneliner中的 shell 变量中删除的行数?ed我正在寻找类似的东西:
n_del=4; ed -s file.txt <<< $'1,\${n_del}d\nwq'
虽然在 shell 中连接以不同方式引用甚至不引用的字符串是完全正常的,所以它可能看起来像:
$ n_del=4; ed -s test <<< "1,${n_del}"d$'\n'wq
我相信,here-doc 会比 one-liner 更干净:
$ n_del=4 $ ed -s test <<_EOF 1,${n_del}d wq _EOF