开发者

Insert newline before first line

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 sta开发者_如何转开发ndard (GNU) UNIX utilities?


For variety:

echo | cat - file


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.


A $ before a single-quoted string will cause bash to interpret escape sequences within it.

sed -e '1 i'$'\n'


You could use awk:

$ awk 'FNR==1{print ""} 1' file

Which will work with any number of files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜