[olug] Unix Tip: INSERT A LINE

Jay Hannah jay at jays.net
Sat Mar 29 14:31:30 UTC 2003


Unix Guru Universe wrote:
> INSERT A LINE
> 
> If you want to insert a line
> at the top (or anywhere for that
> matter) of a file within a shell
> script, use the ed editor.
> 
> EXAMPLE:
> 
> string="hello"
> ed << EOF
> e any_file
> 1i
> ${string}


Mongers would:

   perl -pi -e 'print "hello\n" unless $cnt++' any_file

Cheers,

Jay
Omaha Perl Mongers: http://omaha.pm.org


More information about the OLUG mailing list