I have a list of base64-encoded file names in the pattern of {base64-encoded part here}_2015-11-12.pdf
. I'm trying to decode that list of files and return it on the command line as another list, separated by newlines. Here's what I'm trying now:
find . -name "*_*" -printf "%f\0" | sed 's/_....-..-..\.pdf//g' | xargs -0 -i echo "{}" | base64 -d
I think what I'm doing here is . . .
- finding the files, printing out only the file's name (i.e., stripping off the "./" prefix) separated by a null character
- using sed to preserve only the base64-encoded part (i.e., removing the
_2015-11-12.pdf
part of the file's name) - using xargs to ostensibly pass each file name to echo
- then decoding the value returned by echo.
The result of that is apparently a big string of all of the base64-decoded file names, each name separated by a null character, with the entire string followed by a newline. The desired result would be each individual decoded file name on a line by itself.
I've tried all kinds of tricks to try and fix this but I haven't found anything that works. I've tried ... | base64 -d | echo
, ... | base64 -d && echo
, etc., trying to insert a newline at various points along the way. It seems like by the time the values end up at | base64 -d
, they are all processed at once, as a single string. I'm trying to find a way to send each value to base64 -d
one at a time, NOT as a monolithic list of file names.