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.
我ed在 bash 脚本中使用来搜索文件;该/命令将显示我不想要的内容。我试图重定向>/dev/null 2>&1,但这对我不起作用。
ed
/
>/dev/null 2>&1
foo.txt
a b c
bar.sh
ed -s foo.txt << EOF /b/ EOF > /dev/null 2>&1
$ ./bar.sh b
如何停止ed打印匹配的行b?
b
我想你的意思是:
ed -s foo.txt > /dev/null <<eof /b/ eof
您可以使用ed注释命令 /b/;#移动到匹配的行而不打印结果。
/b/;#
根据ed文档
'(.,.)#' 开始评论;该行的其余部分(直到换行符)被忽略。如果给出后跟分号的行地址,则当前地址设置为该地址。否则,当前地址不变。
'(.,.)#'
开始评论;该行的其余部分(直到换行符)被忽略。如果给出后跟分号的行地址,则当前地址设置为该地址。否则,当前地址不变。