1

Trying to replace a pattern inside text lines with a pattern found at the very beginning of the same line.

Having some text:

number4456 reports a high level of error
number3458 taking a proper error warning
number9273 is not an error prone software

Desired output:

reports a high level of error_number4456
taking a proper error_number3458 warning
is not an error_number9273 prone software

2 Answers 2

1

With sed:

LC_ALL=C sed -e 's/^\([^ ]*\) \(.* error\)/\2_\1/' <file

assuming that there's only one error occurs in a line.

0
awk '{a = "";for(i=2;i<=NF;i++){if($i ~ /error/)a = a$i"_"$1" ";else a = a$i" "}print a}' yourfile

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .