This will modify your file and leave a copy of the original in filename.csv.bak
perl -ni.bak -e 'print "PREFIX $_"' filename.csvThe "code" (rather than "one liner") equivelent of [tirwhan]'s example:
use strict;
use warnings;
local @ARGV = ('file.csv');
local $^I = '.bak';
while (<>)
{
print "prepended stuff - $_";
}
perl -pi.bak -e 's/^/PREFIX/' filename.csv
Loading 20MB in the memory will speed up the things, but there are some problems related with that:
Anyway, do not use REGEX to prepend the variable there. REGEX is a cool thing, but is a mistake to use REGEX as the solution for everything. In your case, a very simple print will do, so I using REGEX?
As a hint, try to use print like this:
print $prepend_value, $line_from_file, "\n";Instead of:
print "$prepend_value$line_from_file\n";Usually using print with multiple arguments is faster them concatenating strings and print after that. Use Benchmark to test the speed of different methods.
perlmonks.org content © perlmonks.org and awohld, blazar, Enlil, glasswalk3r, GrandFather, tirwhan
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03