awk: print column number (example 1-100), not total number of columns

With Google I found this command {print NF} to show total number of columns:

$ nova list | awk '{print NF}' | sort -n | uniq
1
9
10

But I wish to print for every column their number. See example with field seperator |

$ nova list | head
+--------------------------------------+-----------------------------------------+--------+----------------------------------------------+
| ID                                   | Name                                    | Status | Networks                                     |
+--------------------------------------+-----------------------------------------+--------+----------------------------------------------+
| 45bd0bc3-96b4-4193-ae76-59115b4ee528 | rert                                    | ACTIVE | netblock5=192.168.0.10                 |
| 6682aa37-b766-437e-9b16-ce1076ce2410 | test5                                   | ACTIVE | netblock5=192.168.0.110                |
| 6f08fcf3-ea71-4f33-a01a-9b0712385511 | test2                                   | ACTIVE | netblock5=192.168.0.111                |
| 8f628408-1ace-4792-85b6-e134fe1f07cb | test55                                  | ACTIVE | netblock5=192.168.0.52, 192.168.222.46 |
| 458aa8cb-42c2-4aa6-ab30-c6858bcd85f3 | derggdre                                | ACTIVE | netblock5=192.168.0.63, 192.168.222.49 |
| 67f4bd0c-0e4d-4ba1-8765-dc7d7831c8f8 | dgrfdrf                                 | ACTIVE | netblock5=192.168.1.86                 |
| 846ffa7d-76a4-4c70-8d82-23b5a205ad77 | ttttt                                   | ACTIVE | netblock5=192.168.1.27                 |
  1                                     2                                          3        4


Source: shell

Leave a Reply