For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2004 > Re: Field as single letter









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: Field as single letter
Ulrich M. Schwarz

2004-09-03, 8:55 pm

Maedowan <Maedowan@gaz.pl> writes:

> i need Fields to be single letters in gawk i make it like this
>
> awk -v FS '' '{print $2}' #it prints second letter of every line


Well, that didn't even work for my GNU Awk 3.1.3:
: ~ [0 502]; awk -v FS '' '{print $2}'
awk: `FS' argument to `-v' not in `var=value' form

What you can do, in a pinch, is:
awk --posix '{split($0, line, ""); print line[2];}'
which, on casual inspection, worked here.

HTH
Ulrich
--
The Bastard Flatmate From Hell:
"Positive traits? My flatmate?
He's off on vacation for four ws, does that count?"
http://www.informatik.uni-kiel.de/~ums/bffh1.html
Kenny McCormack

2004-09-03, 8:55 pm

In article <rg8n02-c23.ln1@invisibletruth.510081182724.dialin.t-online.de>,
Ulrich M. Schwarz <brotherelf@gmx.net> wrote:
>Maedowan <Maedowan@gaz.pl> writes:
>
>
>Well, that didn't even work for my GNU Awk 3.1.3:
>: ~ [0 502]; awk -v FS '' '{print $2}'
>awk: `FS' argument to `-v' not in `var=value' form


I think an = sign got dropped from his post, probably b/c of newsreader
settings.

A more straightforward way to test this is:

gawk '{print $2}' FS=

>What you can do, in a pinch, is:
>awk --posix '{split($0, line, ""); print line[2];}'
>which, on casual inspection, worked here.


Interesting. You'd think the two would be equivalent (they certainly are
supposed to be - but I'm not all that surprised that POSIX got it wrong).

Note that the OP's requirement that it "work on every platform" is a tall
order. For example, the following won't work on an unpatched/unhacked
Solaris system:

awk '{split($0,l,"");print l[2]}'

Maedowan

2004-09-03, 8:55 pm

Kenny McCormack wrote:


>
> I think an = sign got dropped from his post, probably b/c of newsreader
> settings.


you're right, there must be an = sign

> A more straightforward way to test this is:
>
> gawk '{print $2}' FS=
>
>
> Interesting. You'd think the two would be equivalent (they certainly are
> supposed to be - but I'm not all that surprised that POSIX got it wrong).
>
> Note that the OP's requirement that it "work on every platform" is a tall
> order. For example, the following won't work on an unpatched/unhacked
> Solaris system:
>
> awk '{split($0,l,"");print l[2]}'


why it won't work? isn't there split function in standard?

P.S sorry if my english is hard to understand it'm trying to improve it.
Kenny McCormack

2004-09-03, 8:55 pm

In article <chat6i$mg3$1@inews.gazeta.pl>, Maedowan <Maedowan@gaz.pl> wrote:
....
>
>why it won't work? isn't there split function in standard?


The point I was trying to make, somewhat obliquely, is that the awk on
Solaris (that which you get by default, unless you change your PATH or do
other adjustments), is very "sub-standard" (speaking both literally and
figuratively...). So, in general, you won't be able to have a shell
command that starts with "awk" do anything particularly useful on "all
platforms" - if that phrase is meant to include a standard Solaris system.

So, lest you think this is just sophistry, my real point is that you might
as well assume gawk everywhere (installing it if necessary) and go from there.

>P.S sorry if my english is hard to understand it'm trying to improve it.


It's not that bad. You seem to be doing OK.

Maedowan

2004-09-04, 8:55 am

Kenny McCormack wrote:

> In article <chat6i$mg3$1@inews.gazeta.pl>, Maedowan <Maedowan@gaz.pl>
> wrote: ...
>
> The point I was trying to make, somewhat obliquely, is that the awk on
> Solaris (that which you get by default, unless you change your PATH or do
> other adjustments), is very "sub-standard" (speaking both literally and
> figuratively...). So, in general, you won't be able to have a shell
> command that starts with "awk" do anything particularly useful on "all
> platforms" - if that phrase is meant to include a standard Solaris system.
>
> So, lest you think this is just sophistry, my real point is that you might
> as well assume gawk everywhere (installing it if necessary) and go from
> there.


i didn't now that, i think i should ask how to chop input to single letters
using awk interpreter, which is compatible with posix standards
Brian Inglis

2004-09-04, 3:55 pm

On Sat, 04 Sep 2004 02:29:25 +0200 in comp.lang.awk, Maedowan
<Maedowan@gaz.pl> wrote:

>Kenny McCormack wrote:
>
>
>i didn't now that, i think i should ask how to chop input to single letters
>using awk interpreter, which is compatible with posix standards


Default awk on Solaris is old awk, before functions etc.; nawk (new
awk) on Solaris is what everyone else refers to as awk, as described
in the AWK book, and in the POSIX standard.
Solution is add 'alias awk nawk' to your Solaris ~/.login or
'alias awk=nawk' in your Solaris ~/.profile.

--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada

Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]a
b[dot]ca)
fake address use address above to reply
Sponsored Links







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

Copyright 2008 codecomments.com