Adding specific text and spaces to each line in a text file

Hi,

I wanted to add specific text to each row in a text file containing three rows. Example:

0 8 7 6 5 5
7 8 9 0 7 9
7 8 9 0 1 2

And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this:

21 0 8 7 6 5 5
7 8 9 0 7 9
7 8 9 0 1 2

Thanks in advance!

This is a clunky sed script to do what you want -

sed '1s/^/21 /;2s/^/ /;3s/^/ /' filename > newfilename

With some basic commands:

echo -n '21 ';cat file > newfile

Regards

awk '{if ( NR == 1 ){print 21,$0}else{print " " $0}}' name_of_file

Thanks!