the script is running normally on ubuntu Linux and i can call bin_packing.awk, but when I try to run it on unix solaris I'm getting an error:
find: bad option -printf find: [-H | -L] path-list predicate-list awk: syntax error near line 1 awk: bailing out near line 1
this is the script that works on ubuntu
$ find . -type f -iname '*pdf' -printf "%s %p\n" \
| awk -v c=100000 -f bin_packing.awk
i have tried this and it works but without | awk...part
$ find . -type f -name '*.pdf' -print | perl -lne '$,=" "; @s=stat $_; print $s[7],$_' \
| awk -v c=100000 -f bin_packing.awk
On modern systems, you can use GNU stat
or GNU find
to extract size without needing to do something awful like parse ls
.
Unfortunately, you're not on a modern system, so it's time to do something awful. Fortunately, size is one of the fields of ls
that can be semi-reliably parsed (when running it over only one file at a time) as long as you're on a platform that doesn't allow crazy things like usernames with spaces.
find . -type f -iname '*.pdf' -exec bash -c '
for name; do
read -r _ _ _ _ size _ < <(ls -l -- "$name")
printf "%s %s\n" "$size" "$name"
done
' _ {} + | awk -v c=100000 -f bin_packing.awk
If -exec ... {} +
syntax doesn't work, you can change the +
to a \;
to make this slower but more compatible.