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
but i need it to works on every platform, when i add option --posix it
doesn't work, what should i change to make it work on posix systems?
|
|
0
|
|
|
|
Reply
|
Maedowan
|
9/3/2004 10:03:32 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 weeks, does that count?"
http://www.informatik.uni-kiel.de/~ums/bffh1.html
|
|
0
|
|
|
|
Reply
|
brotherelf
|
9/3/2004 10:40:59 PM
|
|
In article <rg8n02-c23.ln1@invisibletruth.510081182724.dialin.t-online.de>,
Ulrich M. Schwarz <brotherelf@gmx.net> wrote:
>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
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]}'
|
|
0
|
|
|
|
Reply
|
gazelle
|
9/3/2004 10:55:46 PM
|
|
Kenny McCormack wrote:
>>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.
you're right, there must be an = sign
> 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]}'
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.
|
|
0
|
|
|
|
Reply
|
Maedowan
|
9/3/2004 11:03:05 PM
|
|
In article <chat6i$mg3$1@inews.gazeta.pl>, Maedowan <Maedowan@gaz.pl> wrote:
....
>> 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?
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.
|
|
0
|
|
|
|
Reply
|
gazelle
|
9/4/2004 12:05:28 AM
|
|
Kenny McCormack wrote:
> In article <chat6i$mg3$1@inews.gazeta.pl>, Maedowan <Maedowan@gaz.pl>
> wrote: ...
>>> 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?
>
> 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
|
|
0
|
|
|
|
Reply
|
Maedowan
|
9/4/2004 12:29:25 AM
|
|
{
print substr($0, 2, 1)
}
DKM
On Sat, 04 Sep 2004 00:03:32 +0200, Maedowan <Maedowan@gaz.pl> wrote:
>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
>
>but i need it to works on every platform, when i add option --posix it
>doesn't work, what should i change to make it work on posix systems?
To contact me directly, send EMAIL to (single letters all)
DEE_KAY_EMM AT EarthLink.net. [For example X_X_X@EarthLink.net.]
|
|
0
|
|
|
|
Reply
|
Doug
|
9/4/2004 1:48:40 AM
|
|
In article <iq7ij0h1js8npgu5n8vfta2ghb5qp87v98@4ax.com>,
Doug McClure <Dee_Kay_Emm@EarthLink.net> wrote:
>{
>print substr($0, 2, 1)
>}
Well, yeah, but that's not the point.
|
|
0
|
|
|
|
Reply
|
gazelle
|
9/4/2004 1:55:18 AM
|
|
On Sat, 04 Sep 2004 02:29:25 +0200 in comp.lang.awk, Maedowan
<Maedowan@gaz.pl> wrote:
>Kenny McCormack wrote:
>
>> In article <chat6i$mg3$1@inews.gazeta.pl>, Maedowan <Maedowan@gaz.pl>
>> wrote: ...
>>>> 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?
>>
>> 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
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]ab[dot]ca)
fake address use address above to reply
|
|
0
|
|
|
|
Reply
|
Brian
|
9/4/2004 1:55:48 AM
|
|
|
8 Replies
130 Views
(page loaded in 0.746 seconds)
|