Issue
To guess what's happening with some KDE applications doing weird things, I created a one line command to have a list of all files that are not located by a desktop application when I just launch and close it.
I use strace
output as source of data to be processed, as lines below:
openat(AT_FDCWD, "/usr/share/nvidia/nvidia-application-profiles-rc", O_RDONLY) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/usr/X11R6/lib/X11/fonts/.uuid", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/var/cache/fontconfig/0bcde688-f6c6-45d7-9a5c-9a93ce4e186f-x86_64.cache-7", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/usr/lib64/qt5/plugins/platformthemes/KDEPlasmaPlatformTheme.so.avx2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/etc/nvidia/nvidia-application-profiles-rc", O_RDONLY) = -1 ENOENT (No existe el fichero o el directorio)
I want to get a list of all not found files/folders in a text row and I got it with:
strace **DAN** 2>&1 | awk -v FS="," '/openat/ && /No existe/ {print substr($2, 3, length($2) - 3)} ' | sort | uniq -u | awk 'BEGIN{FS="/"; ORS=" "} {print $NF}'
where DAN is a desktop application name as "kate", "libreoffice" or anyone.
Note: /No existe/ is like /Doesn't exist/ or /Not found/
I'm sure that this command could be simplified, avoiding two "awk" commands, but don't know how. I use "sort" and "uniq" cause I don't want repeated filenames.
Anyone could simplify this?
Thank you in advance
Solution
Assuming your file names do not contain double quotes and the only double quotes in the matching lines are around the file name, you could use the double quotes as field separator, rework $2
and use the result as the key of an associative array (for the uniqueness):
$ strace **DAN** 2>&1 | awk -F'"' '
/^openat.*No existe/ {sub(/(.*\/)?/,"",$2); f[$2]}
END {for(k in f) printf("%s ", k); print}'
.uuid 0bcde688-f6c6-45d7-9a5c-9a93ce4e186f-x86_64.cache-7 nvidia-application-profiles-rc KDEPlasmaPlatformTheme.so.avx2
Answered By - Renaud Pacalet