我目前正在处理一个shell脚本,其中有时可能会将错误输出到文件中,但我需要移动错误,因为它不代表任何操作,一切正常只要错误不存在。在bash脚本中使用sed从文件中删除一行
我有具有以下的脚本:
ftp ftp://$2:[email protected]$1 <<BLOCK> $5
cd "$4"
ls
quit
BLOCK
$ 5是FTP命令的输出写入文件。因此,在该文件中,我有以下
total 8
-rw-r--r-- 1 root root 42 Dec 17 14:26 test1.txt
-rw-r--r-- 1 root root 6 Dec 17 14:08 test2.txt
有时我得到的错误?Invalid command.
所以我用sed
从文件中删除错误。我已经将shell脚本更改为以下内容。测试注意事项我已将error
放入FTP中以确保我收到上述错误消息。
ftp ftp://$2:[email protected]$1 <<BLOCK> $5
cd "$4"
ls
error
quit
BLOCK
fileout=$(sed '/?Invalid command./d' $5)
echo $fileout > $5
这是工作在这个意义上,我删除了错误信息,但它也消除了换行,所以当我看一下这个文件,我得到以下
total 8 -rw-r--r-- 1 root root 42 Dec 17 14:26 test1.txt -rw-r--r-- 1 root root 6 Dec 17 14:08 test2.txt
如何保持线路休息?
感谢您提供的任何帮助。
报价'sed'的输出是绝对荒谬的。这正是管道的用途。 –