在第一行添加空格,在所有其他行添加另一个空格
Add spaces to first line and another amount of spaces to all other lines
我有一个文件,我需要为第一行放置 7 个空格,为所有其他行放置 3 个空格。
所以我这样做了(我把 1d 忽略了第一行):
sed -i '1 s/^/ /' $f
sed -i '1d s/^/ /' $f
它适用于第一行空格,但另一个给我这个错误:
sed: -e expression #1, char 4: extra characters after command
sed '
# more spaces for the first line
1s/^/ /
# less spaces for all the other lines.
1!s/^/ /
'
您可以在 https://www.grymoire.com/Unix/Sed.html#uh-25 https://www.gnu.org/software/sed/manual/sed.html 学习 sed。
您也可以像减法一样,在第一行添加 4 个空格,然后在所有地方添加 3 个空格。 1s/^/ /;s/^/ /
我有一个文件,我需要为第一行放置 7 个空格,为所有其他行放置 3 个空格。
所以我这样做了(我把 1d 忽略了第一行):
sed -i '1 s/^/ /' $f
sed -i '1d s/^/ /' $f
它适用于第一行空格,但另一个给我这个错误:
sed: -e expression #1, char 4: extra characters after command
sed '
# more spaces for the first line
1s/^/ /
# less spaces for all the other lines.
1!s/^/ /
'
您可以在 https://www.grymoire.com/Unix/Sed.html#uh-25 https://www.gnu.org/software/sed/manual/sed.html 学习 sed。
您也可以像减法一样,在第一行添加 4 个空格,然后在所有地方添加 3 个空格。 1s/^/ /;s/^/ /