让我清除换行符:
$ echo Hello > file1 ; cat file1
Hello
$ echo -n  Hello > file2 ; cat file2
Hello$ 在这里,您可以看到file1结尾处有换行符,而结尾file2没有。
现在假设我有一个file:
$ cat file
Hello
Welcome to
Unix
$我想and Linux在文件末尾添加,然后echo " and Linux" >> file将其添加到换行符。但我要最后一行Unix and Linux
因此,为了变通,我想在文件末尾删除换行符。因此,如何删除文件末尾的换行符?
sed '$s/$/ and linux/'