Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 复制、粘贴并回显到包含换行符的txt文件中_Bash_Shell_Echo - Fatal编程技术网

Bash 复制、粘贴并回显到包含换行符的txt文件中

Bash 复制、粘贴并回显到包含换行符的txt文件中,bash,shell,echo,Bash,Shell,Echo,我正在做一个关于命令行的教程。在其中一个练习中,我被要求复制粘贴一个文件并将其粘贴到一个新文件中。 问题是新文件中没有新行,事实上,当我cat文件时,每一节都附加到前一节 是否必须在每行末尾手动添加“\n”? 我希望有更好的方法(因为如果有1000行呢?) 更新: 这就是我到现在为止所做的 首先,我抄袭了他的十四行诗。然后我将其粘贴到终端中,以编写以下命令: ~$ echo "FRom faireſt creatures we deſire increaſe, That thereby beau

我正在做一个关于命令行的教程。在其中一个练习中,我被要求复制粘贴一个文件并将其粘贴到一个新文件中。 问题是新文件中没有新行,事实上,当我
cat
文件时,每一节都附加到前一节

是否必须在每行末尾手动添加
“\n”
? 我希望有更好的方法(因为如果有1000行呢?)

更新: 这就是我到现在为止所做的

首先,我抄袭了他的十四行诗。然后我将其粘贴到终端中,以编写以下命令:

~$ echo "FRom faireſt creatures we deſire increaſe, That thereby beauties Roſe might neuer die, But as the riper ſhould by time deceaſe, His tender heire might beare his memory: But thou contracted to thine owne bright eyes, Feed’ſt thy lights flame with ſelfe ſubſtantiall fewell, Making a famine where aboundance lies, Thy ſelfe thy foe,to thy ſweet ſelfe too cruell: Thou that art now the worlds freſh ornament, And only herauld to the gaudy ſpring, Within thine owne bud burieſt thy content, And tender chorle makſt waſt in niggarding:    Pitty the world,or elſe this glutton be,    To eate the worlds due,by the graue and thee." > sonnet.txt
最后我检查一下内容:

cat sonnet.txt
但我得到:

FRom faireſt creatures we deſire increaſe, That thereby beauties Roſe might neuer die, But as the riper ſhould by time deceaſe, His tender heire might beare his memory: But thou contracted to thine owne bright eyes, Feed’ſt thy lights flame with ſelfe ſubſtantiall fewell, Making a famine where aboundance lies, Thy ſelfe thy foe,to thy ſweet ſelfe too cruell: Thou that art now the worlds freſh ornament, And only herauld to the gaudy ſpring, Within thine owne bud burieſt thy content, And tender chorle makſt waſt in niggarding:    Pitty the world,or elſe this glutton be,    To eate the worlds due,by the graue and thee.

这将适用于十四行诗:)

我想你错过了双引号

$ echo $sonnet
Shall I compare thee to a summer.s day? Thou art more lovely and more temperate. Rough winds do shake the darling buds of May,

没有复制粘贴一首十四行诗。十四行诗是一个字符文件还是别的什么?你用什么命令来做这个<代码>回显[粘贴]>文件?粘贴的内容在每一节之间都有空行吗?@Mahendra,对不起,我忘了放一个链接,它不起作用。请看链接(我忘了放在前面)。尝试复制和粘贴它,然后将其回显到txt文件中。你是如何保持新词的?不管你用哪首十四行诗/哪段文字。你注意到这些引语了吗?定义变量和回显变量时。请发布您在原始帖子中使用的确切命令。也许你在做别的事情。在第2页突出显示十四行诗。ctrl-c,3。输入终端“echo”,4。键入“$[粘贴]”,5。键入“>sonnet.txt”,6。单击ENTER是否键入双引号以包装在步骤4中粘贴的文本?你能像我在回答中所做的那样将你的命令复制/粘贴到原始帖子(不是在评论中)吗?看起来你的复制/粘贴没有保留换行符。当你粘贴到记事本上时,你看到的是相同的吗?
$ echo $sonnet
Shall I compare thee to a summer.s day? Thou art more lovely and more temperate. Rough winds do shake the darling buds of May,