f



awk

I have the following gawk script that I came up with on my linux box that
works and I'd like to be able to use it on my iBook but from the manpage
for awk the FIELDWIDTH variable isn't supported. Can the script be easily 
converted to awk from gawk? Or should I look for a gawk implementation for 
OSX?

{ FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }

{ print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}

I know the length of each field, but the fields aren't necessarially
seperated by white space.


-- 
clear skies,
Joe

http://mysite.verizon.net/jringer3/astro1.htm
0
joe1782 (21)
2/22/2006 8:20:54 PM
comp.sys.mac.system 33446 articles. 2 followers. jfmezei.spamnot (9455) is leader. Post Follow

10 Replies
540 Views

Similar Articles

[PageSpeed] 20

In article <slrndvphtf.7pg.joe@speedy.ringer.home>,
 Joe R <joe@speedy.ringer.home> wrote:

> I have the following gawk script that I came up with on my linux box that
> works and I'd like to be able to use it on my iBook but from the manpage
> for awk the FIELDWIDTH variable isn't supported. Can the script be easily 
> converted to awk from gawk? Or should I look for a gawk implementation for 
> OSX?
> 
> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
> 
> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
> 
> I know the length of each field, but the fields aren't necessarially
> seperated by white space.

awk and Sun's nawk don't support FIELDWIDTHS.  According the the gawk 
documentation:

http://www.cs.utah.edu/dept/old/texinfo/gawk/gawk_toc.html

neither does gawk.  So I think you're stuck with staying on the Linux 
system for the moment.  Leastways, you can convert the script to perl 
then it will run on Linux and MacOS X.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...



0
vilain (1505)
2/22/2006 9:49:55 PM
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--0-1029921211-1140648693=:22687
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: 8BIT

Wed, 22 Feb 2006 (13:49 -0800 UTC) Michael Vilain wrote:

> In article <slrndvphtf.7pg.joe@speedy.ringer.home>,
> Joe R <joe@speedy.ringer.home> wrote:
>
>> I have the following gawk script that I came up with on my linux box that
>> works and I'd like to be able to use it on my iBook but from the manpage
>> for awk the FIELDWIDTH variable isn't supported. Can the script be easily
>> converted to awk from gawk? Or should I look for a gawk implementation for
>> OSX?
>>
>> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
>>
>> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
>>
>> I know the length of each field, but the fields aren't necessarially
>> seperated by white space.
>
> awk and Sun's nawk don't support FIELDWIDTHS.  According the the gawk
> documentation:
>
> http://www.cs.utah.edu/dept/old/texinfo/gawk/gawk_toc.html
>
> neither does gawk.  So I think you're stuck with staying on the Linux
> system for the moment.  Leastways, you can convert the script to perl
> then it will run on Linux and MacOS X.

GNU Awk 3.1.5 running on OS X 10.4.5 knows FIELDWIDTHS

% echo "0123456678901234566789123456678912345667891234566789123456678912345667891234566789123456678912345667891234566789123456678901234566789012345667891234566789123456678912345667891234566789123456678912345667891234566789123456678912345667891234566789"\ 
| gawk 'BEGIN { FIELDWIDTHS = "7 22 9 7 18 48 8 25" } { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}'
0123456 ; 6789012345667891234566 ; 789123456 ; 6789123 ; 456678912345667891 ;91234566 ;

I installed in via darwinports.

-- 
  oK+++
   Life can only be understood backwards; but it must be lived forwards.
                                                      -S�ren Kierkegaard
--0-1029921211-1140648693=:22687--
0
vapaa (83)
2/22/2006 10:51:33 PM
Joe R wrote:
> I have the following gawk script that I came up with on my linux box that
> works and I'd like to be able to use it on my iBook but from the manpage
> for awk the FIELDWIDTH variable isn't supported. Can the script be easily 
> converted to awk from gawk? Or should I look for a gawk implementation for 
> OSX?
> 
> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
> 
> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
> 
> I know the length of each field, but the fields aren't necessarially
> seperated by white space.
> 
> 
You can use the substr() function
fld1 = substr($0,1,7)
fld2 = substr($0,8,22)
etc.
0
nschrems (14)
2/23/2006 2:47:09 AM
Ned Schrems wrote:
> Joe R wrote:
> 
>> I have the following gawk script that I came up with on my linux box that
>> works and I'd like to be able to use it on my iBook but from the manpage
>> for awk the FIELDWIDTH variable isn't supported. Can the script be 
>> easily converted to awk from gawk? Or should I look for a gawk 
>> implementation for OSX?
>>
>> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
>>
>> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
>>
>> I know the length of each field, but the fields aren't necessarially
>> seperated by white space.
>>
>>
> You can use the substr() function
> fld1 = substr($0,1,7)
> fld2 = substr($0,8,22)
> etc.

Here's a more elegant solution

BEGIN   {
         FIELDWIDTHS = "7 22 9 7"
         split(FIELDWIDTHS,len," ")
         for(k=1;k<=4;k++)
                 print k,len[k]
         }

         {
         start = 1
         for(k=1;k<=4;k++)
                 {
                 fld[k] = substr($0,start,len[k])
                 start += len[k]
                 print fld[k]
                 }
         }

Next step would be to take the seconnd paragraph and put it in a 
function, but I'll leave that for a homework exercise :<))
0
nschrems (14)
2/23/2006 3:14:06 AM
In article <Pine.OSX.4.64L.0602221741230.22687@kneh.vj.yd>,
 Obfus Kataa <vapaa@finhut.fi.example.com> wrote:

> Wed, 22 Feb 2006 (13:49 -0800 UTC) Michael Vilain wrote:
> 
> > In article <slrndvphtf.7pg.joe@speedy.ringer.home>,
> > Joe R <joe@speedy.ringer.home> wrote:
> >
> >> I have the following gawk script that I came up with on my linux box that
> >> works and I'd like to be able to use it on my iBook but from the manpage
> >> for awk the FIELDWIDTH variable isn't supported. Can the script be easily
> >> converted to awk from gawk? Or should I look for a gawk implementation for
> >> OSX?
> >>
> >> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
> >>
> >> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
> >>
> >> I know the length of each field, but the fields aren't necessarially
> >> seperated by white space.
> >
> > awk and Sun's nawk don't support FIELDWIDTHS.  According the the gawk
> > documentation:
> >
> > http://www.cs.utah.edu/dept/old/texinfo/gawk/gawk_toc.html
> >
> > neither does gawk.  So I think you're stuck with staying on the Linux
> > system for the moment.  Leastways, you can convert the script to perl
> > then it will run on Linux and MacOS X.
> 
> GNU Awk 3.1.5 running on OS X 10.4.5 knows FIELDWIDTHS
> 
> % echo 
> "01234566789012345667891234566789123456678912345667891234566789123456678912345
> 667891234566789123456678912345667891234566789012345667890123456678912345667891
> 234566789123456678912345667891234566789123456678912345667891234566789123456678
> 91234566789"\ 
> | gawk 'BEGIN { FIELDWIDTHS = "7 22 9 7 18 48 8 25" } { print $1, ";",  $2, 
> | ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}'
> 0123456 ; 6789012345667891234566 ; 789123456 ; 6789123 ; 456678912345667891 
> ;91234566 ;
> 
> I installed in via darwinports.

gawk 3.1.2 on MacOS X 10.3.9 also works but it's not in the docs 
anywhere that FIELDWIDTHS is supported (not in the page I quoted nor in 
the manpages installed on the system).  Did you wander through the 
source to find this out (obviously, I didn't bother and I do apologize).

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...



0
vilain (1505)
2/23/2006 9:21:53 AM
On Wed, 22 Feb 2006 21:14:06 -0600, Ned Schrems wrote:
>
>
> Ned Schrems wrote:
>> Joe R wrote:
>> 
>>> I have the following gawk script that I came up with on my linux box that
>>> works and I'd like to be able to use it on my iBook but from the manpage
>>> for awk the FIELDWIDTH variable isn't supported. Can the script be 
>>> easily converted to awk from gawk? Or should I look for a gawk 
>>> implementation for OSX?
>>>
>>> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
>>>
>>> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
>>>
>>> I know the length of each field, but the fields aren't necessarially
>>> seperated by white space.
>>>
>>>
>> You can use the substr() function
>> fld1 = substr($0,1,7)
>> fld2 = substr($0,8,22)
>> etc.
>
> Here's a more elegant solution
>
> BEGIN   {
>          FIELDWIDTHS = "7 22 9 7"
>          split(FIELDWIDTHS,len," ")
>          for(k=1;k<=4;k++)
>                  print k,len[k]
>          }
>
>          {
>          start = 1
>          for(k=1;k<=4;k++)
>                  {
>                  fld[k] = substr($0,start,len[k])
>                  start += len[k]
>                  print fld[k]
>                  }
>          }
>
> Next step would be to take the seconnd paragraph and put it in a 
> function, but I'll leave that for a homework exercise :<))

Worked like a charm and didn't require using up a bunch of my iBooks
limited hd. Thanks.


-- 
clear skies,
Joe

http://mysite.verizon.net/jringer3/astro1.htm
0
joe1782 (21)
2/23/2006 5:06:45 PM
Thu, 23 Feb 2006 (01:21 -0800 UTC) Michael Vilain wrote:

> In article <Pine.OSX.4.64L.0602221741230.22687@kneh.vj.yd>,
>  Obfus Kataa <vapaa@finhut.fi.example.com> wrote:
> 
> > Wed, 22 Feb 2006 (13:49 -0800 UTC) Michael Vilain wrote:
> >
> >> In article <slrndvphtf.7pg.joe@speedy.ringer.home>,
> >> Joe R <joe@speedy.ringer.home> wrote:
> >>
> >>> I have the following gawk script that I came up with on my linux box that
> >>> works and I'd like to be able to use it on my iBook but from the manpage
> >>> for awk the FIELDWIDTH variable isn't supported. Can the script be easily
> >>> converted to awk from gawk? Or should I look for a gawk implementation for
> >>> OSX?
> >>>
> >>> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
> >>>
> >>> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
> >>>
> >>> I know the length of each field, but the fields aren't necessarially
> >>> seperated by white space.
> >>
> >> awk and Sun's nawk don't support FIELDWIDTHS.  According the the gawk
> >> documentation:
> >>
> >> http://www.cs.utah.edu/dept/old/texinfo/gawk/gawk_toc.html
> >>
> >> neither does gawk.  So I think you're stuck with staying on the Linux
> >> system for the moment.  Leastways, you can convert the script to perl
> >> then it will run on Linux and MacOS X.
> >
> > GNU Awk 3.1.5 running on OS X 10.4.5 knows FIELDWIDTHS
> >
> > % echo
> > "01234566789012345667891234566789123456678912345667891234566789123456678912345
> > 667891234566789123456678912345667891234566789012345667890123456678912345667891
> > 234566789123456678912345667891234566789123456678912345667891234566789123456678
> > 91234566789"\
> > | gawk 'BEGIN { FIELDWIDTHS = "7 22 9 7 18 48 8 25" } { print $1, ";",  $2,
> > | ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}'
> > 0123456 ; 6789012345667891234566 ; 789123456 ; 6789123 ; 456678912345667891
> > ;91234566 ;
> >
> > I installed in via darwinports.
> 
> gawk 3.1.2 on MacOS X 10.3.9 also works but it's not in the docs
> anywhere that FIELDWIDTHS is supported (not in the page I quoted nor in
> the manpages installed on the system).  Did you wander through the
> source to find this out (obviously, I didn't bother and I do apologize).

No, I tried `man gawk':
/FIELDWITHS\n
FIELDWIDTHS    A white-space  separated  list  of fieldwidths.  When set,
                gawk parses the input into fields of fixed  width, instead
                of using the value of the FS variable as the field separa-
                tor.
10.4.5 appears not to have a system-installed gawk, only awk.
% where gawk
/opt/local/bin/gawk
/opt/bin/gawk

-- 
  oK+++
0
vapaa (83)
2/26/2006 6:37:01 PM
In article <Pine.OSX.4.64L.0602261329110.1883@fkgkfbhxo.rs>,
 Obfus Kataa <vapaa@finhut.fi.example.com> wrote:

> Thu, 23 Feb 2006 (01:21 -0800 UTC) Michael Vilain wrote:
> 
> > In article <Pine.OSX.4.64L.0602221741230.22687@kneh.vj.yd>,
> >  Obfus Kataa <vapaa@finhut.fi.example.com> wrote:
> > 
> > > Wed, 22 Feb 2006 (13:49 -0800 UTC) Michael Vilain wrote:
> > >
> > >> In article <slrndvphtf.7pg.joe@speedy.ringer.home>,
> > >> Joe R <joe@speedy.ringer.home> wrote:
> > >>
> > >>> I have the following gawk script that I came up with on my linux box 
> > >>> that
> > >>> works and I'd like to be able to use it on my iBook but from the 
> > >>> manpage
> > >>> for awk the FIELDWIDTH variable isn't supported. Can the script be 
> > >>> easily
> > >>> converted to awk from gawk? Or should I look for a gawk implementation 
> > >>> for
> > >>> OSX?
> > >>>
> > >>> { FIELDWIDTHS = "7 22 9 7 18 48 8 25 7 3 15 1 2 2 2 2 2 2 2 2 2 30" }
> > >>>
> > >>> { print $1, ";",  $2, ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}
> > >>>
> > >>> I know the length of each field, but the fields aren't necessarially
> > >>> seperated by white space.
> > >>
> > >> awk and Sun's nawk don't support FIELDWIDTHS.  According the the gawk
> > >> documentation:
> > >>
> > >> http://www.cs.utah.edu/dept/old/texinfo/gawk/gawk_toc.html
> > >>
> > >> neither does gawk.  So I think you're stuck with staying on the Linux
> > >> system for the moment.  Leastways, you can convert the script to perl
> > >> then it will run on Linux and MacOS X.
> > >
> > > GNU Awk 3.1.5 running on OS X 10.4.5 knows FIELDWIDTHS
> > >
> > > % echo
> > > "0123456678901234566789123456678912345667891234566789123456678912345667891
> > > "2345
> > > 66789123456678912345667891234566789123456678901234566789012345667891234566
> > > 7891
> > > 23456678912345667891234566789123456678912345667891234566789123456678912345
> > > 6678
> > > 91234566789"\
> > > | gawk 'BEGIN { FIELDWIDTHS = "7 22 9 7 18 48 8 25" } { print $1, ";",  
> > > | $2,
> > > | ";", $3, ";", $4, ";", $5, ";" $7, ";",  $8}'
> > > 0123456 ; 6789012345667891234566 ; 789123456 ; 6789123 ; 
> > > 456678912345667891
> > > ;91234566 ;
> > >
> > > I installed in via darwinports.
> > 
> > gawk 3.1.2 on MacOS X 10.3.9 also works but it's not in the docs
> > anywhere that FIELDWIDTHS is supported (not in the page I quoted nor in
> > the manpages installed on the system).  Did you wander through the
> > source to find this out (obviously, I didn't bother and I do apologize).
> 
> No, I tried `man gawk':
> /FIELDWITHS\n
> FIELDWIDTHS    A white-space  separated  list  of fieldwidths.  When set,
>                 gawk parses the input into fields of fixed  width, instead
>                 of using the value of the FS variable as the field separa-
>                 tor.
> 10.4.5 appears not to have a system-installed gawk, only awk.
> % where gawk
> /opt/local/bin/gawk
> /opt/bin/gawk

I apparently don't have the man pages for gawk when I installed it with 
fink which is why I used the net's version.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...



0
vilain (1505)
2/27/2006 8:00:31 AM
In article <vilain-F24E54.00003127022006@comcast.dca.giganews.com>,
 Michael Vilain <vilain@spamcop.net> wrote:

> I apparently don't have the man pages for gawk when I installed it with 
> fink which is why I used the net's version.

If you installed gawk with fink, its man pages are probably located in 
/sw/share/man/.  You might want to check your MANPATH environment 
variable to see if it includes the path to fink installed man pages.

-- 
Tom Stiller

PGP fingerprint =  5108 DDB2 9761 EDE5 E7E3 
                   7BDA 71ED 6496 99C0 C7CF
0
tomstiller (3053)
2/27/2006 11:57:15 AM
In article <tomstiller-3A6EA0.06571427022006@comcast.dca.giganews.com>,
 Tom Stiller <tomstiller@comcast.net> wrote:

> In article <vilain-F24E54.00003127022006@comcast.dca.giganews.com>,
>  Michael Vilain <vilain@spamcop.net> wrote:
> 
> > I apparently don't have the man pages for gawk when I installed it with 
> > fink which is why I used the net's version.
> 
> If you installed gawk with fink, its man pages are probably located in 
> /sw/share/man/.  You might want to check your MANPATH environment 
> variable to see if it includes the path to fink installed man pages.

did a find / -name "*gawk*" 

and all it found was the gawk program in /usr/local/bin.  I don't think 
fink installs it there, does it?  It would probably go in /sw/bin/.  
Searching versiontracker didn't come up with a packaged version of gawk, 
so I guess I'll have to pull the source tarball from gnu.org and extract 
the man page.

Thanks for the help...

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...



0
vilain (1505)
2/27/2006 7:56:03 PM
Reply: