Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Print tab-separated details for the given file based on the package that owns it
- # Usage:
- # awk -v file=/path/to/some/file -f find.awk /lib/apk/db/installed
- BEGIN {
- # multi-line records, go!
- RS=""
- # our input fields are lines, but our output is tab-delimited
- OFS="\t"
- # This is a big long ugly chunk of string manipulation to basically split "/usr/bin/ls" in to ["usr/bin", "ls"]
- # There are easier ways to do this in other languages, but I'm not sure if that's the case for awk :-(
- ofile = file
- while (file ~ /^\//)
- file = substr(file, 2)
- p = split(file, parts, "/")
- dirname = ""
- for (i = 0; i <= p; i++) {
- if (parts[i] ~ /^\s*$/)
- continue
- if (i == p)
- filename = parts[i]
- else
- dirname = dirname "/" parts[i]
- }
- dirname = substr(dirname, 2)
- # the trailing \\n is so we do an exact match on the path
- # otherwise /usr/bin/foo will match /usr/bin/foobar and /usr/binaries/foo
- # This is a side effect of how the package files are recorded in the APK db
- dirpat = "F:" dirname "\\n"
- filepat = "R:" filename "\\n"
- }
- # match any record that has both the directory and filename listed for it
- $0 ~ dirpat && $0 ~ filepat {
- for (i = 0; i < NF; i++)
- f[substr($i, 0, 1)] = substr($i, 3)
- print f["P"], f["V"], f["U"], f["L"], ofile
- }
Add Comment
Please, Sign In to add comment