insert new line using SED
As part of a script, I need to:
Search a file for a string.
Extract part of that string.
Use that part string in a new line.
Insert that new line just before the original line.
Linux
As part of a script, I need to:
Search a file for a string.
Extract part of that string.
Use that part string in a new line.
Insert that new line just before the original line.
by nico baggus
I thing this is above en beyond the ability of
sed: but perl can help you here....
---8<---
#!perl -w
$match = $ARGV[0];
$file = $ARGV[1];
if (not defined $file) {
$file = "-";
}
open(IN,"<".$file) || die ("Cannot open file:
$file\n");
while ($line = ) {
if ($line =~ /($match)/) {
# here you can do something you
needed to extract...
print $1,"\n";
}
print $line;
}
close IN;
by stevelil
by stevelil
This discussion is closed to new replies.
Sort by Trending