$ sudo lsof -u t | grep -i "\.pdf" evince 1788 t 37r REG 8,4 176328 134478 /home/t/some/path1/white space/string1 + string2 string3.pdf evince 3737 t 36r REG 8,4 1252636 6692680 /home/t/some/path2/white space/string5 string3.pdf How can I extract only the second column (pids of processes)?
How can I extract only the ninth column (pathnames of files)? (pathnames can contain any character allowed by Linux and ext4 file systems)
My real command is
$ sudo lsof -u t | grep -v "wineserv" | grep REG | grep "\.pdf" | grep "string" where I would search for records whose first column "COMMAND" isn't wineserv, and fifth column "TYPE" is REG, and whose ninth column "NAME" contains .pdf and string.
Prefer bash, awk or Python solutions (and maybe Perl, but I don't know Perl, so won't be able to verify if it is correct or modify it later)
Thanks.
lsofhas-Fflag according to the manual, so you could dolsof -F pto get just the PID itself. Let me know if you want that as an answer, but of course I can do Python and awk parsing as wellfind /proc/*/fd -ilname '*.pdf' 2>/dev/null | awk -F/ '{print$3}'(btw, this will also work if the filenames contain newline, spaces, etc).