tr命令无法直接输出? [英] tr command not able to direct the Output?

查看:61
本文介绍了tr命令无法直接输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件 file.txt 女巫有这些条目

I have got a file file.txt witch has got these entries

纽约

LA

SF

我运行了命令tr'\ n'',<file.txt并成功删除了所有换行符.

I ran the command tr '\n' ',' < file.txt and it successfully deleted all of the newline characters.

我需要所有这些输出都放在同一个file.txt文件中,因此我将输出重定向为这样

I need all of this output in the same file.txt file, so I redirected the output like this

tr'\ n'',<file.txt>file.txt,

tr '\n' ',' < file.txt > file.txt,

但是它没有在file.txt中放置任何内容,并且结果文件为空,谁能向我解释为什么 tr 的输出由于重定向而丢失.

but It does not put anything in the file.txt and the resultant file is empty, Can anyone explain to me why the output of tr is getting lost due to redirection.

推荐答案

因为它首先打开输出文件,该文件删除了文件中的内容,然后对tr命令没有任何感觉,然后又返回到空文件中

because it opens the output file first which deletes what is in the file and then feels nothing into the tr command and back out into the empty file

tr '\n' ',' < file.txt > file2.txt 

将起作用

这篇关于tr命令无法直接输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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