As a first project for learning awk, I wanted to reformat the output of the wmctrl command, which can be installed like this in Debian 11:
sudo apt install wmctrl
To list information about all the windows I have open, I run this command:
wmctrl -lpG
Sample Output:
0x0120002b 4 7 2 157 3836 2068 my-pc window - AWK - Dealing with spaces in the last column of output from wmctrl - Unix & Linux Stack Exchange — Firefox
I never can remember what each column means, in the command above, so I wanted to break it apart into name/value pairs, using AWK:
wmctrl -lpG | awk '{print "----------------------\nWindow ID: " $1 "\nDesktop Number: " $2 "\nProcess ID: " $3 "\nx-offset: " $4 "\ny-offset: " $5 "\nwidth: " $6 "\nheight: " $7 "\nMachine Name: " $8 "\nWindow Title: " $9}'
Sample Output:
----------------------
Window ID: 0x0120002b
Desktop Number: 4
Process ID: 7
x-offset: 2
y-offset: 134
width: 3836
height: 2068
Machine Name: my-pc
Window Title: window
Desired Output:
----------------------
Window ID: 0x0120002b
Desktop Number: 4
Process ID: 7
x-offset: 2
y-offset: 134
width: 3836
height: 2068
Machine Name: my-pc
Window Title: window - AWK - Dealing with spaces in the last column of output from wmctrl - Unix & Linux Stack Exchange — Firefox
However, I'm having trouble figuring out how to handle the 9th Column outputted by wmctrl -lpG (because the 9th column contains spaces). Notice that I'm only getting the first word of the window title instead of the whole window title.
Is there an easy way to remedy this issue?