Re: to replace a field of a line - help

From: Stefan Lagotzki (lago20_at_gmx.de)
Date: 03/04/04


Date: Thu, 04 Mar 2004 14:06:18 +0100


   spanda <spanda@cisco.com>:
> I want to replace a field of a line without knowing the content of the
> field.
> i.e if a line is "he is a good guy" and I want to replace the 4th field
> (good) and the new line
> should be "he is a nice guy".

awk '{gsub(/good/,"nice",$4);print}' input.txt > output.txt

Test:

echo "he is a good guy" | awk '{gsub(/good/,"nice",$4);print}'
he is a nice guy

HTH,
Stefan

.