【发布时间】:2019-02-05 21:58:39
【问题描述】:
我知道如何从 .txt 数据中获取例如前 2 行并将其附加到 .txt 数据的末尾。但是我应该如何将 .txt 数据的最后 2 行添加到 .txt 数据的第 1 行
我试过了:
tail -n 2 test1.txt >> head test1.txt # takes last 2 lines of text and adding
it to the head
看起来非常错误,但我在任何地方都找不到答案,用尾巴和头来做。
tail n 2 test1.txt >> head test1.txt
cat test1.txt
请有人更正我的代码,以便我得到预期的结果。
【问题讨论】:
-
你可以这样做:
(tail -n 2 test1.txt && cat test1.txt) >> test.tmp.txt && mv test.tmp.txt test1.txt -
标题不应该只描述问题是关于什么的,而应该描述问题本身,这样其他人就可以判断它的答案是否会是对自己的问题有帮助。我试图为此进行编辑。