Usenet comp.unix.osf.misc (1992-2004)
 help / color / mirror / Atom feed
* AWK on digital UNIX.
@ 1997-03-05  5:00 rchannav
  1997-03-06  5:00 ` Mark Katz
  1997-03-07  5:00 ` Pete Ford
  0 siblings, 2 replies; 4+ messages in thread
From: rchannav @ 1997-03-05  5:00 UTC (permalink / raw)



Hi All,

Recently I had to write a script in awk on DIGITAL - UNIX 4.0.
I was surprised by this ambiguous output and see if it is the
way in DIGITAL UNIX.  The code segment is as follows

awk -F\, '{
		.......

		gsub(/ /,//,$2)
		print $0

		.......
	}' < /tmp/tmp.txt

the tmp.txt is like this

hello,fo o,123
foo,bar,123
bar,ba r,123 etc.,

Basically I am stripping the blanks from second field.  The output it
produces is in the following format

hello,fo10,123
foo,bar,123
bar,ba1r,123

I know that gsub returns the no.of occurences, but why in $2??

Thanks

-- 
--------------------------------------------------------
You might be a redneck if you think I speak for NCR
--------------------------------------------------------



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: AWK on digital UNIX.
  1997-03-05  5:00 AWK on digital UNIX rchannav
@ 1997-03-06  5:00 ` Mark Katz
  1997-03-06  5:00   ` Mark Katz
  1997-03-07  5:00 ` Pete Ford
  1 sibling, 1 reply; 4+ messages in thread
From: Mark Katz @ 1997-03-06  5:00 UTC (permalink / raw)



In article <331DC423.38DB@rpspo2.atlantaga.ncr.com>
           rchannav@rpspo2.atlantaga.ncr.com  writes:

>Recently I had to write a script in awk on DIGITAL - UNIX 4.0.
>I was surprised by this ambiguous output and see if it is the
>way in DIGITAL UNIX.  The code segment is as follows
>
>awk -F\, '{
>                gsub(/ /,//,$2)
>                print $0
>        }' < /tmp/tmp.txt
>
>the tmp.txt is like this
>
>hello,fo o,123
>foo,bar,123
>bar,ba r,123 etc.,
>
>Basically I am stripping the blanks from second field.  The output it
>produces is in the following format
>
>hello,fo10,123            ****<- do you mean hello,fo1o,123
>foo,bar,123
>bar,ba1r,123
>
>I know that gsub returns the no.of occurences, but why in $2??

I find this very hard to believe!
What else do you do in the program. gsub does **not** return the number
of substitutions it does.

If no-one else suggest what is happening, send me the entire program
with some real data and we'll check it out on *real* awk compiler/interpreters!

Mark
-- 
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** Visit our website on http://www.efiche.com/efiche **




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: AWK on digital UNIX.
  1997-03-06  5:00 ` Mark Katz
@ 1997-03-06  5:00   ` Mark Katz
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Katz @ 1997-03-06  5:00 UTC (permalink / raw)



I posted a reply to this mail which contained incorrect
information about awk (sorry awk! - I had just got off a plane
from New York > London and was suffering for a sleepless/uncomfortable
flight - thanks to American!)

gsub does indeed return the number of substitutions it carried out.
I tried your program on MKS-DOS-AWK and it replaced each space with the 
digit '1' - ie a  b -> a11b
Not that I fully understand why
Is that what you got?

When I changed it to "'s - ie gsub(" ", "", $2) it worked as desired

Mark
>In article <331DC423.38DB@rpspo2.atlantaga.ncr.com>
>           rchannav@rpspo2.atlantaga.ncr.com  writes:
>
>>Recently I had to write a script in awk on DIGITAL - UNIX 4.0.
>>I was surprised by this ambiguous output and see if it is the
>>way in DIGITAL UNIX.  The code segment is as follows
>>
>>awk -F\, '{
>>                gsub(/ /,//,$2)
>>                print $0
>>        }' < /tmp/tmp.txt
>>
>>the tmp.txt is like this
>>
>>hello,fo o,123
>>foo,bar,123
>>bar,ba r,123 etc.,
>>
>>Basically I am stripping the blanks from second field.  The output it
>>produces is in the following format
>>
>>hello,fo10,123            ****<- do you mean hello,fo1o,123
>>foo,bar,123
>>bar,ba1r,123
>>
>>I know that gsub returns the no.of occurences, but why in $2??

-- 
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** Visit our website on http://www.efiche.com/efiche **




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: AWK on digital UNIX.
  1997-03-05  5:00 AWK on digital UNIX rchannav
  1997-03-06  5:00 ` Mark Katz
@ 1997-03-07  5:00 ` Pete Ford
  1 sibling, 0 replies; 4+ messages in thread
From: Pete Ford @ 1997-03-07  5:00 UTC (permalink / raw)



rchannav@rpspo2.atlantaga.ncr.com wrote:
> 
> Hi All,
> 
> Recently I had to write a script in awk on DIGITAL - UNIX 4.0.
> I was surprised by this ambiguous output and see if it is the
> way in DIGITAL UNIX.  The code segment is as follows
> 
> awk -F\, '{
>                 .......
> 
>                 gsub(/ /,//,$2)
>                 print $0
> 
>                 .......
>         }' < /tmp/tmp.txt
> 
> the tmp.txt is like this
> 
> hello,fo o,123
> foo,bar,123
> bar,ba r,123 etc.,
> 
> Basically I am stripping the blanks from second field.  The output it
> produces is in the following format
> 
> hello,fo10,123
> foo,bar,123
> bar,ba1r,123
> 
> I know that gsub returns the no.of occurences, but why in $2??
> 
> Thanks
> 
> --
> --------------------------------------------------------
> You might be a redneck if you think I speak for NCR
> --------------------------------------------------------
From the man page:

Substitutes the string repl in place of the first instance
of the extended regular expression ERE in string in and return the
number of substitutions.

That is, the second argument of 'sub' and 'gsub' is a *string*, not a
regular expression. 
So your gsub line should read:
	gsub(/,/,"",$2)
The '1' appears to be the result of a match of the second regular
expression - in the case of // this always matches. But putting /_/ (for
example) in as the second parameter puts a '0' in the spaces, and
putting /a/ in puts a '0' in the first example line, and a 1 in the
third line.
Hmmm...

-- 
Pete Ford	Unix Sys. Admin.	Oxford University Computing Services
Phone: +44 1865 2~73266 		Look mum, a real job!
"I'm sorry but you need more help than I can give you over the phone"-
R. Letts
The above message represents my personal opinion; neither my employers,
nor any other organisation, is responsible for statements made therein



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-03-07  5:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-03-05  5:00 AWK on digital UNIX rchannav
1997-03-06  5:00 ` Mark Katz
1997-03-06  5:00   ` Mark Katz
1997-03-07  5:00 ` Pete Ford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox