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

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

问题描述

我有一个文件TEMP.TXT,我想在bash的排序命令排序。

我要排序的结果来替换原来的文件。

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

  sortx TEMP.TXT> TEMP.TXT

这能在一行中做,而不诉诸复制到临时文件?


编辑: -o 选项是排序非常酷。我用排序在我作为一个例子问题。我碰到了同样的问题与其他命令:

  uniq的TEMP.TXT> TEMP.TXT。

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


解决方案

 排序TEMP.TXT -o TEMP.TXT

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?


EDIT: 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天全站免登陆