Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Field as single letter
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

Report this thread to moderator Post Follow-up to this message
Old Post
Ulrich M. Schwarz
09-04-04 01:55 AM


Re: Field as single letter
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]}'


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
09-04-04 01:55 AM


Re: Field as single letter
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Maedowan
09-04-04 01:55 AM


Re: Field as single letter
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 ther
e.

>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.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
09-04-04 01:55 AM


Re: Field as single letter
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

Report this thread to moderator Post Follow-up to this message
Old Post
Maedowan
09-04-04 01:55 PM


Re: Field as single letter
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

Report this thread to moderator Post Follow-up to this message
Old Post
Brian Inglis
09-04-04 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:02 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.