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 15:01:18 +0100

Hi Subrat,

   spanda <spanda@cisco.com>:
> Here the point is I don't know the content of the 4th field ie. good.
> And I want to replace it directly with a new word.

echo "he is a good guy" | awk '{$4="nice";print}'
he is a nice guy

awk '{$4="nice";print}' input.txt > output.txt

With a modern Version of awk you may use:

awk -v replace_string="nice" '{$4=replace_string;print}' input > output

Stefan

.