我如何“就地"执行编辑其文件(参数)的任何命令?使用 bash? [英] How do I execute any command editing its file (argument) "in place" using bash?

查看:12
本文介绍了我如何“就地"执行编辑其文件(参数)的任何命令?使用 bash?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件 temp.txt,我想用 bash 中的 sort 命令对其进行排序.

I have a file temp.txt, that I want to sort with the sort command in bash.

我希望排序结果替换原始文件.

I want the sorted results to replace the original file.

例如这不起作用(我得到一个空文件):

This doesn't work for example (I get an empty file):

sortx temp.txt > temp.txt

这是否可以在一行中完成而无需复制到临时文件?

Can this be done in one line without resorting to copying to temporary files?

-o 选项对于 sort 来说非常酷.我在我的问题中使用了 sort 作为示例.我在使用其他命令时遇到了同样的问题:

The -o option is very cool for sort. I used sort in my question as an example. I run into the same problem with other commands:

uniq temp.txt > temp.txt.

有没有更好的通用解决方案?

Is there a better general solution?

推荐答案

sort temp.txt -o temp.txt

这篇关于我如何“就地"执行编辑其文件(参数)的任何命令?使用 bash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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