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

Rich Shepard rshepard at appl-ecosys.com
Mon Jul 23 20:08:23 UTC 2018


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.

Many thanks,

Rich


More information about the SlackBuilds-users mailing list