我有一个 .txt 文件,我将其放入另一个 .txt 文件中。
原始文件 (final.txt) 的最后一行以“拉特=”然后通过应用 cat,得到下面的数字“拉特=”已添加,如下所示。
问题是 cat 将新数据放置在“lats =”下方。
cat initial.txt >> final.txt
有没有我可以使用的标志,以便 cat 将新数据放在与“lats =”同一行?
我拥有的:
12.54000000 12.98000000 12.98000000 12.54000000
lats =
9.90000000 10.34000000 10.34000000 9.90000000
10.34000000 10.78000000 10.78000000 10.34000000
10.78000000 11.22000000 11.22000000 10.78000000
11.22000000 11.66000000 11.66000000 11.22000000
11.66000000 12.10000000 12.10000000 11.66000000
12.10000000 12.54000000 12.54000000 12.10000000
12.54000000 12.98000000 12.98000000 12.54000000
我需要的:
12.54000000 12.98000000 12.98000000 12.54000000
lats = 9.90000000 10.34000000 10.34000000 9.90000000
10.34000000 10.78000000 10.78000000 10.34000000
10.78000000 11.22000000 11.22000000 10.78000000
11.22000000 11.66000000 11.66000000 11.22000000
11.66000000 12.10000000 12.10000000 11.66000000
12.10000000 12.54000000 12.54000000 12.10000000
12.54000000 12.98000000 12.98000000 12.54000000
答案1
sed
附加后立即应用特定替换:
$ cat initial.txt >> final.txt
$ sed -Ei '/^lats =/N; s/\n\s{6}//' final.txt