Extracting column of a column in awk?

  • A+
Category:Languages

In the below example I end of with an output of 3000 x 3000, where it is temping to run awk again to get just the width and height as variables without white space.

$ cat << EOF >> /tmp/test File name       : Graf3.png File size       : 84937 Bytes MIME type       : image/png Image size      : 3000 x 3000 EOF $ cat /tmp/test | awk -F':' '/Image size/ {print $2}'  3000 x 3000 

Question

Is there a way to get the width and height without calling awk again?

 


Assuming you want the values in shell rather than awk variables:

$ dim=( $( awk '/Image size/{print $(NF-2), $NF}' file ) ) $ declare -p dim declare -a dim=([0]="3000" [1]="3000") 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: