how to insert a string as a first line of the file

Hi
I need to update a number of existing files and insert #!/bin/ksh line a the first line of the file.
Is there any awk or sed command which would help me to do that instead of doing it manually?
Thanks a lot -A

If your sed supports the -i switch, you can do:

sed -i '1i\#!/bin/ksh' infile

No, -i is not supported by sed :frowning:

Then you can do like this:

sed -i '1i\#!/bin/ksh' infile > temp_file;mv temp_file infile

Or with ed

<some "ls" command that gets the files you want> | while read FILE; do
  ed $FILE << !
1i
#!/bin/ksh
.
w
q
!
done
perl -i~ -0777pe's/^/\#\!\/bin\/ksh\n/' file

Thanks a lot guys! It worked

Just want to add a note that Perl code can be written in a more elegant way like below:-

perl -i -0777 -pe  's:^:#!/bin/ksh\n:' infile.txt

;):wink:

sed '1s|^|#!/bin/ksh\n|' infile

True, here another one:

perl -pi -e 'print "#!/bin/ksh\n" if $. == 1' file
echo '#!/bin/ksh' | cat - file