[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] gsub inbuilt function
From: |
Aharon Robbins |
Subject: |
Re: [bug-gawk] gsub inbuilt function |
Date: |
Wed, 05 Mar 2014 06:27:48 +0200 |
User-agent: |
Heirloom mailx 12.5 6/20/10 |
Hello. Apologies for the delay in replying.
> Date: Mon, 24 Feb 2014 21:52:02 +0530
> Subject: Re: [bug-gawk] gsub inbuilt function
> From: Ujjwal Kumar <address@hidden>
> To: Aharon Robbins <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1
>
> For example:
> echo "kjlsdkj lkjlsj slkjljls replace field1 field2 dkjkdh" | awk
> '{gsub ("replace","replacewith", $4); print $0}'
>
> Gives this as output -- notice that the space b/w "field1" and
> "field2" has been reduced to 1:
>
> kjlsdkj lkjlsj slkjljls replacewith field1 field2 dkjkdh
>
> And here is the version I am using:
> GNU Awk 3.1.6
> Copyright (C) 1989, 1991-2007 Free Software Foundation.
The problem is that you are modifying one of the fields. Once you
do that, gawk rebuilds the record, separating the fields with
instances of OFS. This is described in the manual.
If you modify a regular variable, you won't see this:
$ cat x.in
kjlsdkj lkjlsj slkjljls replace field1 field2 dkjkdh
$ cat x.awk
{
text = $0
gsub ("replace","replacewith", text); print text
gsub ("replace","replacewith", $4); print $0
}
$ gawk-3.1.6 -f x.awk x.in
kjlsdkj lkjlsj slkjljls replacewith field1 field2 dkjkdh
kjlsdkj lkjlsj slkjljls replacewith field1 field2 dkjkdh
By the way, 3.1.6 is quite old. You should consider upgrading.
Thanks,
Arnold
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [bug-gawk] gsub inbuilt function,
Aharon Robbins <=