I\'m having little problem with bash/sed. I need to be able to use command substitution within sed expression. I have two big text files:
first is logfile.t
I don't know if this would work, since I can't get an answer on whether or not capture groups persist, but there is a lot more to sed than just the s command. I was thinking you could use a capture group in a regex line selector, then use that for the command substitution. Something like this:
/ERRORID:\(0x[0-9a-f]*\)/ s/ERRORID:0x[0-9a-f]*/ERROR:$(grep \1 errors.txt | grep -o '^[A-Z_]*' )/
Anyway, if that doesn't work I would change gears and point out that this is really a good job for Perl. Here's how I would do it, which I think is much cleaner / easier to understand:
#!/usr/bin/perl
while(<>) {
while( /ERRORID:(0x[0-9a-f]*)/ ) {
$name = system("grep $1 errors.txt | grep -o '^[A-Z_]*'");
s/ERRORID:$1/ERROR:$name/g;
}
print;
}
Then execute:
./thatScript.pl logfile.txt