Reputation: 3
I am trying to insert a newline before the first line of text in a file. The only solution i have found so far is this:
sed -e '1 i
')
I do not like to have an actual newline in my shell script. Can this be solved any other way using the standard (GNU) UNIX utilities?
Upvotes: 0
Views: 3607
Reputation: 103834
You could use awk:
$ awk 'FNR==1{print ""} 1' file
Which will work with any number of files.
Upvotes: 1
Reputation: 86333
Here's a pure sed solution with no specific shell requirements:
sed -e '1 s|^|\n|'
EDIT:
Please note that there has to be at least one line of input for this (and anything else using a line address) to work.
Upvotes: 3
Reputation: 798636
A $
before a single-quoted string will cause bash to interpret escape sequences within it.
sed -e '1 i'$'\n'
Upvotes: 2