and -i flag to edit files in-place (see perlrun for more). Use $. to check the line number. Define BEGIN{} to read the header, then write it in the main loop:LINE: while (<>) { ... # your program goes here } continue { print or die "-p destination: $!\n"; }
Perhaps avoiding the -p will be more efficient, but not so compact:perl -pi -e'BEGIN{$HEAD=shift@ARGV;open(HEAD);$main::head=<HEAD>}$_=$m +ain::head.$_ if $.==1' header-file file-to-be-edited
Warning: both of the one-liners use somewhat deprecated one-argument open and barewords as filehandles.perl -e'($HEAD,$FILE)=@ARGV;open(HEAD);open(FILE);open($f,">$FILE.$$") +;print $f scalar <HEAD>,<FILE>;rename "$FILE.$$","$FILE"' header-file + file-to-be-edited
In reply to Re: Single line insert to the start of a file
by aitap
in thread Single line insert to the start of a file
by darklord_999
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |