如何将此awk命令的输出保存到文件? [英] How to save the output of this awk command to file?
问题描述
我想将此命令保存为另一文本: awk'{print $ 2}' 它从文本中提取. 现在我想将输出另存为文本. 谢谢
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 }' text.txt > outputfile.txt
>
=>这会将STDOUT
重定向到文件.如果文件不存在,它将创建它.如果文件存在,它将清除(实际上)内容并向其中写入新数据
>
=> 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
>>
=>这与上面的意思相同,但是如果文件存在,它将向其添加新数据.
>>
=> This means same as above but if file exists, this will append new data to it.
例如:
Eg:
$ cat /etc/passwd | awk -F: '{ print $1 }' | tail -10 > output.txt
$ cat output.txt
_warmd
_dovenull
_netstatistics
_avbdeviced
_krb_krbtgt
_krb_kadmin
_krb_changepw
_krb_kerberos
_krb_anonymous
_assetcache
或者,您可以使用命令tee
进行重定向. tee
命令会将STDOUT
重定向到指定文件以及终端屏幕
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
有关外壳重定向的更多信息,请转到以下链接:
For more about shell redirection goto following link:
http://www.techtrunch.com/scripting/redirections-and-file-descriptors
这篇关于如何将此awk命令的输出保存到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!