From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4AB1FB95.4070005@maht0x0r.net> Date: Thu, 17 Sep 2009 10:04:21 +0100 From: matt User-Agent: Mozilla Thunderbird 1.0.6 (X11/20060326) MIME-Version: 1.0 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [9fans] awk help; not plan9 matter Topicbox-Message-UUID: 6fc2901e-ead5-11e9-9d60-3106f5b1d025 awk '{a=$2; sub(a, "hell"); print}' file also works if it contains no regex special chars this seems to do the trick otherwise awk ' { p=substr($0, index($0, " ")); split(p, a, "[^ ]"); sub(/ +[^ ]+/, "", p); print $1 a[1] "hell" p} ' Rudolf Sykora wrote: >Hello, > >simple task. >I want to change the 2nd field on each line of a file, but preserve >the spacing of the lines. > >If I do > awk '{$2="hell"; print}' file >the field gets changed, but all the spacing of the lines is gone; i.e. >any space is now just ' ' like this: >1 3 4 8 >changes to >1 hell 4 8 >while I need >1 hell 4 8. > >Any help? >Thanks >Ruda > > >