For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2006 > Re: FS = "[:space:]" versus FS ~ "[:space:]"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: FS = "[:space:]" versus FS ~ "[:space:]"
Jon LaBadie

2006-09-12, 6:56 pm

Andrzej wrote:
> Hi
> My next problem
>
> Simple script:
> ************
> BEGIN {FS = "[:space:]"; OFS = ";"} ;
> {
>
> print $1, $2, $3, $4, $5, $6
>
> }
> ************
>
> Sample data:
> *****************
> 1 2 3 4 5 6
> 2 3 4 5 6 1
> 3 4 5 6 1 2
> 4 5 6 1 2 3
> 6 7 7 8 9 8
> *****************
>
> Result:
>
> C:\temp\gawk\bin>gawk -f s\2.txt filename
> 1 2 3 4 5 6;;;;;
> 2 3 4 5 6 1;;;;;
> 3 4 5 6 1 2;;;;;
> 4 5 6 1 2 3;;;;;
> 6 7 7 8 9 8;;;;;
>
> Ughh....
> However, when first line changed to:
>
> *****
> BEGIN {FS ~ "[:space:]"; OFS = ";"} ;
> *****
>
> script works like a charm.
> Now, why? "~" is matching operator, not assignment one... I tried all
> combinations with "=" and "[:space:]" but this doesn't work.
> Using gawk 3.1.3 on Windows.
>


The second works because you end up using awk's default FS, whitespace.

The first fails because your gawk doesn't recognize [:space:] as meaning
a single whitespace character. It takes it as the list ':', 's', 'p', 'a'...

You might try it as "[[:space:]]"


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com