Following command doesn’t pick 2nd string from odd line and 4th from odd-even line.
show_statistic.sh | grep -A 1 vlan | awk '{ if ( ( NR % 2 ) == 1 ) { print $2 } else { print $4 } }'
It prints each line’s second and fourth string. What I did wrong?
Following command doesn’t pick 2nd string from odd line and 4th from odd-even line.
Share
It looks like your expected result is from the lines containing “vlan” and the following ones.
Your code will work with an unique response, but with more response than one your differents results will be separated bi a line containig only “–” as documented in grep :
So with this line more you will want the second argument on line 1, 4, 7…
And the fourth on line 2, 5, 8…
So you code can be :
I write a little text file to test :
The result is :