Guest User

Untitled

a guest
Apr 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. # Print tab-separated details for the given file based on the package that owns it
  2. # Usage:
  3. # awk -v file=/path/to/some/file -f find.awk /lib/apk/db/installed
  4.  
  5. BEGIN {
  6. # multi-line records, go!
  7. RS=""
  8. # our input fields are lines, but our output is tab-delimited
  9. OFS="\t"
  10.  
  11. # This is a big long ugly chunk of string manipulation to basically split "/usr/bin/ls" in to ["usr/bin", "ls"]
  12. # There are easier ways to do this in other languages, but I'm not sure if that's the case for awk :-(
  13. ofile = file
  14. while (file ~ /^\//)
  15. file = substr(file, 2)
  16. p = split(file, parts, "/")
  17. dirname = ""
  18. for (i = 0; i <= p; i++) {
  19. if (parts[i] ~ /^\s*$/)
  20. continue
  21. if (i == p)
  22. filename = parts[i]
  23. else
  24. dirname = dirname "/" parts[i]
  25. }
  26. dirname = substr(dirname, 2)
  27. # the trailing \\n is so we do an exact match on the path
  28. # otherwise /usr/bin/foo will match /usr/bin/foobar and /usr/binaries/foo
  29. # This is a side effect of how the package files are recorded in the APK db
  30. dirpat = "F:" dirname "\\n"
  31. filepat = "R:" filename "\\n"
  32. }
  33.  
  34. # match any record that has both the directory and filename listed for it
  35. $0 ~ dirpat && $0 ~ filepat {
  36. for (i = 0; i < NF; i++)
  37. f[substr($i, 0, 1)] = substr($i, 3)
  38. print f["P"], f["V"], f["U"], f["L"], ofile
  39. }
Add Comment
Please, Sign In to add comment