Column is an interesting command – it will turn delimited text into, well, columns. Simply tell it you want a table (-t) and indicate what separator to use (-s). Optionally, you can add table column headers
1 2 3 4 5 6 | [lisa@linux01 ~/] # cat /etc/group | column -t -s : root x 0 root,lisa bin x 1 daemon x 2 ... passim x 987 |
Alternately, you can use -J to get JSON-formatted output. Here you need the –table-columns as a comma delimited list of column names:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | [lisa@linux01 ~/] # cat /etc/group | column -J -s : --table-columns "group,password,gid,members" { "table" : [ { "group" : "root" , "password" : "x" , "gid" : "0" , "members" : "root,lisa" },{ "group" : "bin" , "password" : "x" , "gid" : "1" , "members" : null },{ "group" : "daemon" , "password" : "x" , "gid" : "2" , "members" : null },{ "group" : "passim" , "password" : "x" , "gid" : "987" , "members" : null } ] } |
Which can then be parsed with jq
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | [lisa@linux01 ~/] # cat /etc/group | column -J -s : --table-columns "group,password,gid,members" | jq '[.table[] | {group: .group, members: .members}]' [ { "group" : "root" , "members" : "root,lisa" }, { "group" : "bin" , "members" : null }, { "group" : "daemon" , "members" : null }, { "group" : "passim" , "members" : null } ] |