[Slackbuilds-users] Default Slackware 'gawk' build options affecting output?

David Woodfall dave at dawoodfall.net
Mon Jul 23 20:14:45 UTC 2018


On Monday 23 July 2018 13:08,
Rich Shepard <rshepard at appl-ecosys.com> put forth the proposition:
> On Mon, 23 Jul 2018, David Woodfall wrote:
>
> > > > Try switch (NR) {
>
> Dave,
>
>   That was a type; I meant 'switch (NF)' regardless, ...
>
> > You need to surround your code in extra braces {}
> >
> > {
> > 	<your code>
> > }
>
>   Actually, the solution was to drop the switch statement and use the NF
> result as the pattern. This gave me three lines:
>
> NF == 36 { print $1, $6, $7, $8, $9, $10, $11, $12, $13, $18, $19, $20, $21, $22, $23, $24, $25, $29, $30, $31, $32, $33, $34, $35, $36 }
> NF == 37 { print $1, $6, $7, $8, $9, $10, $11, $12, $13, $19, $20, $21, $22, $23, $24, $25, $26, $30, $31, $32, $33, $34, $35, $36, $37 }
> NF == 38 { print $1, $7, $8, $9, $10, $11, $12, $13, $14, $20, $21, $22, $23, $24, $25, $26, $27, $31, $32, $33, $34, $35, $36, $37, $38 }
>
> and this works.
>
>   Originally, I tested NF in a bash shell script and called separate awk
> scripts for each one. Realizing this was inefficient I combined the three
> scripts and tried to replace the bash if-elif-else conditional with the awk
> switch statement. Using the basic pattern { action } pair is the correct
> approach.

Switch will work with both NF and NR (and usually anything else
that you're likely to throw at it).

The reason for the extra braces if because that entire switch block
is "action" code, and action code belongs in braces.

What you have done now is replace the single switch action with
multiple tests and actions.

-Dave

--

> What does ELF stand for (in respect to Linux?)
ELF is the first rock group that Ronnie James Dio performed with back in
the early 1970's.  In constrast, a.out is a misspelling   of the French word
for the month of August.  What the two have in common is beyond me, but
Linux users seem to use the two words together.
  -- seen on c.o.l.misc

                                                            .--.  oo
                                                           (____)//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'


More information about the SlackBuilds-users mailing list