0

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 ?

boredaf
  • 171
  • 3
  • 7
  • 1
    Does this answer your question? [How to print only last column?](https://unix.stackexchange.com/questions/17064/how-to-print-only-last-column) --- I think all you need to know is how to get a last field. – FelixJN Dec 08 '21 at 11:46

3 Answers3

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
  • 411,918
  • 54
  • 1,065
  • 1,164
1

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
  • 12,616
  • 2
  • 27
  • 48
-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
  • 7