是这样的:
cat "Some text here." > myfile.txt
可能吗?这样myfile.txt的内容现在将被重写为:
Some text here.
这对我不起作用,但也不会抛出任何错误。
对基于cat的解决方案特别感兴趣(不是vim/vi/emacs等)。所有在线的例子都显示cat用于文件输入,而不是原始文本…
是这样的:
cat "Some text here." > myfile.txt
可能吗?这样myfile.txt的内容现在将被重写为:
Some text here.
这对我不起作用,但也不会抛出任何错误。
对基于cat的解决方案特别感兴趣(不是vim/vi/emacs等)。所有在线的例子都显示cat用于文件输入,而不是原始文本…
当前回答
这就是echo所做的:
echo "Some text here." > myfile.txt
其他回答
解决你的问题的方法是:
echo " Some Text Goes Here " > filename.txt
但是如果你想将一个文件的输出重定向到其他文件,或者想将一个文件的输出附加到另一个文件,你可以使用cat命令:
cat filename > newfile——将filename的输出重定向到newfile
cat filename >> newfile——将filename的输出附加到newfile
cat > filename.txt
输入文本 直到EOF 保存文本使用:ctrl+d
如果你想读取。txt文件使用
cat filename.txt
还有一件事。txt不是强制性的,它只是供你参考。
简单地用cat管道echo
例如
echo write something to file.txt | cat > file.txt
使用cat将文本写入文件的另一种方法是这样的
cat >file.txt <<< Write something here
因为没人回答最初的问题。是的。Cat可以用来在没有here doc的情况下将文本写入文件。
cat - >file.txt
This is the world's worst
multiline text editor.
^d