nawk arrays - Unix

This is a discussion on nawk arrays - Unix ; Need some help printing out the 2nd to last field in each line processed by nawk. I can easily separate fields and print any one I specify with nawk 'BEGIN{FS=" "};{print $n}' but since each processed line has a variable ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: nawk arrays

  1. nawk arrays

    Need some help printing out the 2nd to last field in each line
    processed by nawk. I can easily separate fields and print any one I
    specify with

    nawk 'BEGIN{FS=" "};{print $n}'

    but since each processed line has a variable number of fields I need to
    use a regex to point the print functionto that 2nd to last field.

    Can it be done in a single nawk command? If so, what is it? If it needs
    to be done in a nawk script that is ref'd by the command line, what
    woudl that script be?

    Thx in advance,

    Steve


  2. Re: nawk arrays

    Steveje0711 wrote:
    > Need some help printing out the 2nd to last field in each line
    > processed by nawk. I can easily separate fields and print any one I
    > specify with
    >
    > nawk 'BEGIN{FS=" "};{print $n}'
    >
    > but since each processed line has a variable number of fields I need to
    > use a regex to point the print functionto that 2nd to last field.
    >
    > Can it be done in a single nawk command? If so, what is it? If it needs
    > to be done in a nawk script that is ref'd by the command line, what
    > woudl that script be?
    >


    $ nawk '{print $(NF-1)}

    $ man nawk
    /NF


+ Reply to Thread