Reputation: 41
Given a script like this
# I love this comment
echo "Code code code"
# I love this comment more
echo "More code, more code"
I want to automatically change it to
# I love this comment
echo "Code code code"
# I love this comment more
echo "More code, more code"
How do I accomplish that
Upvotes: 2
Views: 97
Reputation: 41456
Here is an awk
awk '/^[[:blank:]]*#/ && NR>1 {$0=RS$0}1' file
# I love this comment
echo "Code code code"
# I love this comment more
echo "More code, more code"
It adds a blank line before every line starting with #
except the first line.
Upvotes: 3
Reputation: 157992
You can use this:
sed '2,$ s/^#/\n#/'
It will add a new line in front of every #
on the beginning of a line, except of the first line.
Upvotes: 5