How to get the second column from command output? How to get the second column from command output? shell shell

How to get the second column from command output?


Use -F [field separator] to split the lines on "s:

awk -F '"' '{print $2}' your_input_file

or for input from pipe

<some_command> | awk -F '"' '{print $2}'

output:

A BCD


If you could use something other than 'awk' , then try this instead

echo '1540 "A B"' | cut -d' ' -f2-

-d is a delimiter, -f is the field to cut and with -f2- we intend to cut the 2nd field until end.


This should work to get a specific column out of the command output "docker images":

REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZEubuntu                              16.04               12543ced0f6f        10 months ago       122 MBubuntu                              latest              12543ced0f6f        10 months ago       122 MBselenium/standalone-firefox-debug   2.53.0              9f3bab6e046f        12 months ago       613 MBselenium/node-firefox-debug         2.53.0              d82f2ab74db7        12 months ago       613 MBdocker images | awk '{print $3}'IMAGE12543ced0f6f12543ced0f6f9f3bab6e046fd82f2ab74db7

This is going to print the third column