I need to do some processing on the list of .so loaded by a process. I tried cut with space as a delimiter but I didn't succeed. How to correctly pipe the output of cat /proc/PID/maps into cut to get the last field ?
Asked
Active
Viewed 6,121 times
3 Answers
2
Getting the last field often is a bit tricky. Options are
awk '{print $NF}' /proc/PID/maps
(note that awk
returns the last field with an entry, this will return 0
instead of an empty field for inode=0 entries)
or double-reversing a line with selecting the first field in between:
rev /proc/PID/maps | cut -d' ' -f1 | rev
Use grep
to match characters except for space, then match till the end of line:
grep -o '[^ ]*$' /proc/PID/maps

FelixJN
- 13,566
1
You can rely on maps
’ fixed padding:
cut -c74- /proc/.../maps
(on 64-bit platforms).
Extracting the last field in all cases, e.g. with awk '{ print $NF }'
, is misleading with maps
since lines can omit the backing file or use (“[heap]” etc.) entirely.

Stephen Kitt
- 434,908
-1
Cut is a bit limited. If you have in file, file: 12345 abcde 12438
you can parse it with cat file | awk '{print $2}'
to get abcde
which you can pipe or redirect.

Brian
- 158