Linux 如何将此 awk 命令的输出保存到文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14660079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to save the output of this awk command to file?
提问by user2034825
I wanna save this command to another text: awk '{print $2}' it extract's from text. now i wanna save output too another text. thanks
我想将此命令保存到另一个文本: awk '{print $2}' 它从文本中提取。现在我也想保存输出另一个文本。谢谢
采纳答案by Suku
awk '{ print }' text.txt > outputfile.txt
>
=> This will redirect STDOUT
to a file. If file not exists, it will create it. If file exists it will clear out (in effect) the content and will write new data to it
>
=> 这将重定向STDOUT
到一个文件。如果文件不存在,它将创建它。如果文件存在,它将清除(实际上)内容并将新数据写入其中
>>
=> This means same as above but if file exists, this will append new data to it.
>>
=> 这与上面的意思相同,但如果文件存在,这将向其追加新数据。
Eg:
例如:
$ cat /etc/passwd | awk -F: '{ print }' | tail -10 > output.txt
$ cat output.txt
_warmd
_dovenull
_netstatistics
_avbdeviced
_krb_krbtgt
_krb_kadmin
_krb_changepw
_krb_kerberos
_krb_anonymous
_assetcache
Alternatively you can use the command tee
for redirection. The command tee
will redirect STDOUT
to a specified file as well as the terminal screen
或者,您可以使用该命令tee
进行重定向。该命令tee
将重定向STDOUT
到指定的文件以及终端屏幕
For more about shell redirection goto following link:
有关 shell 重定向的更多信息,请转到以下链接:
http://www.techtrunch.com/scripting/redirections-and-file-descriptors
http://www.techtrunch.com/scripting/redirections-and-file-descriptors
回答by Damo
回答by INNO TECH
try this command.
试试这个命令。
cat ORGFILENAME.TXT | awk '{print }' > SAVENAME.TXT
thx.
谢谢。