This is a problem I often encounter, this time with the output of
lsof, but I am searching for a general solution for such problems: selecting a column.
Here I try to get the TYPE column of the output of
COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME lsof 16113 root cwd DIR 0,58 40960 7602184 /home/rubo77 lsof 16113 root rtd DIR 259,7 4096 2 / lsof 16113 root 4r FIFO 0,12 0t0 294763 pipe lsof 16113 root 7w FIFO 0,12 0t0 294764 pipe lsof 16648 root rtd DIR 259,7 4096 2 / riot-web 4399 4424 ruben 25u unix 0xffff9543f9ad7000 0t0 53133 type=STREAM thunderbi 4650 5835 ruben DEL REG 259,7 2752546 /usr/share/icons/hicolor/icon-theme.cache ...
lsof|perl -lane 'print $F'
But this sometimes gets the 6th column, sometimes the 5th
I get it with
lsof|cut -c50-54|sort|uniq -c 375 CHR 610 DIR 211 FIFO ...
But this seems a bit unclean because you have to fix the character position.
The main problem is, that in some lines the 5th column is empty
Is there a solution that really selects only the 6th column of an output?
The best solution would be a tool where you just say show the Xth line, where the tool would analyse the first line and automatically detects by analysing the following lines if each column is aligned right, centre or left and then just select the content of that column.