庆典从文件重定向输入回同一个文件 [英] bash redirect input from file back into same file

查看:112
本文介绍了庆典从文件重定向输入回同一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想作为输入的文本从文件中删除该文件中的一行,并发送回输出到同一个文件。沿着这些线路的东西,如果这使得它更清楚。

Basically I want to take as input text from a file, remove a line from that file, and send the output back to the same file. Something along these lines if that makes it any clearer.

grep -v 'seg[0-9]\{1,\}\.[0-9]\{1\}' file_name > file_name

不过,我这样做,当我结束了一个空白文件。
有什么想法?

however, when I do this I end up with a blank file. Any thoughts?

推荐答案

您不能这样做。您可以使用临时文件虽然。

You cannot do that. You can use a temporary file though.

grep -v 'seg[0-9]\{1,\}\.[0-9]\{1\}' file_name > tmpfile
cat tmpfile > file_name

这样,可以考虑使用 mktemp的来创建的 TMPFILE 的但请注意,这不是POSIX。

like that, consider using mktemp to create the tmpfile but note that it's not POSIX.

这篇关于庆典从文件重定向输入回同一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆