How to add one line in the beginning of the file?

Hi gurus,

I need add one new line in the begining of current file.

current file

 
abc
cde
add
xyz

output file

 
newline
abc
cde
add
xyz

thanks in advance.

$ echo "newline" | cat - infile > outfile
$ cat <(echo "newline") infile >outfile
$ awk 'BEGIN{print "newline"}1' infile >outfile
1 Like
sed '1i newline' infile
newline
abc
cde
add
xyz
cat - file <<< newline
1 Like

Thanks for you reply.

when run the command, I got below error.
sed: command garbled: 1i newline

my server is SunOS 5.10 Generic_144488-17 sun4v sparc SUNW,SPARC-Enterprise-T5220

awk 'BEGIN { print "newline" } ; 1' inputfile > outputfile
1 Like

If you want to use sed , this should work:

sed '1i\
newline
' infile