简体   繁体   English

将输出打印到linux中的文本文件中

[英]Print output into a text file in linux

Hello I am trying to get the difference between to text files. 您好我想尝试区分文本文件。 There are a lot of differences and viewing them in terminal is making it volatile since I cannot save them. 有很多不同之处,在终端中查看它们会使它变得不稳定,因为我无法保存它们。 I want to view and save the diff. 我想查看并保存差异。 How would I catch the output and print it to a text file?? 我如何捕获输出并将其打印到文本文件?

Code I am using for getting the diff is diff -i -w -B file1.txt file2.txt 我用来获取差异的代码是diff -i -w -B file1.txt file2.txt

Save to text file: 保存到文本文件:

diff -i -w -B file1.txt file2.txt > diff.txt

Write directly to printer: 直接写入打印机:

diff -i -w -B file1.txt file2.txt | lpr

Write saved text file to printer 将保存的文本文件写入打印机

lpr diff.txt

'Hope that helps .. PSM '希望有所帮助.. PSM

PS: Here's a link on Linux command-line printing: PS:这是Linux命令行打印的链接:

http://tldp.org/HOWTO/Printing-Usage-HOWTO-2.html http://tldp.org/HOWTO/Printing-Usage-HOWTO-2.html

Generally speaking, 一般来说,
command > output.txt
and in your case 在你的情况下
diff -i -w -B file1.txt file2.txt > output.txt

and if you want to append the result 如果你想追加结果
command >> output.txt

Just redirect it to a file: 只需将其重定向到文件:

 diff -i -w -B file1.txt file2.txt > output.diff

If you'd like to know more about redirecting output, the advanced details vary shell-to-shell, but here's a reference for bash and a cheat-sheet for the common stdout/stderr redirects. 如果您想了解有关重定向输出的更多信息,则高级详细信息会因shell而异,但这里是bash参考,以及常见stdout / stderr重定向的备忘单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM