如何在bash脚本中的注释顶部添加空格

Ayo*_*iyi 2 bash sed

给出这样的脚本

# I love this comment
echo "Code code code"
# I love this comment more
echo "More code, more code"
Run Code Online (Sandbox Code Playgroud)

我想自动将其更改为

# I love this comment
echo "Code code code"

# I love this comment more
echo "More code, more code"
Run Code Online (Sandbox Code Playgroud)

我该如何做到这一点

hek*_*mgl 5

你可以用这个:

sed '2,$ s/^#/\n#/' 
Run Code Online (Sandbox Code Playgroud)

#除了第一行之外,它会在行的开头添加一行新行.

  • 或者`/ s\s*#/ \n&/'`如果评论可以缩进 (3认同)
  • +1表示*"行的开头,第一行除外"*.你不希望在`#!/ bin/bash`前插入一个空行 (2认同)