For convenience and speed of debugging my R
code, I decided to create a tiny AWK
script. All it has to do is to decode all base64-encoded names of files (.RData
) in a particular directory. I've tried my best in two attempts. The following are my results so far. Any help will be appreciated!
The first attempt is an AWK
script embedded in a shell
command:
ls -1 ../cache/SourceForge | awk 'BEGIN {FS="."; print ""} {printf("%s", $1); printf("%s", " -> "); print $1 | "base64 -d -"; print ""} END {print ""}'
The resulting output is close to what is needed, however, instead of printing each decoded filename on the same line with the original encoded one, this one-liner prints all decoded names in the end of processing with no output separator at all:
cHJqTGljZW5zZQ== ->
cHViUm9hZG1hcA== ->
dG90YWxEZXZz ->
dG90YWxQcm9qZWN0cw== ->
QWxsUHJvamVjdHM= ->
Y29udHJpYlBlb3BsZQ== ->
Y29udHJpYlByb2Nlc3M= ->
ZG1Qcm9jZXNz ->
ZGV2TGlua3M= ->
ZGV2U3VwcG9ydA== ->
prjLicensepubRoadmaptotalDevstotalProjectsAllProjectscontribPeoplecontribProcessdmProcessdevLinksdevSupport
The second attempt is the following self-contained AWK
script:
#!/usr/bin/gawk -f
BEGIN {FS="."; print ""; files = "ls -1 ../cache/SourceForge"}
{
decode = "base64 -d -";
printf("%s", $1); printf("%s", " -> "); print $1 | decode; print ""
}
END {print ""}
However, this script's behavior is surprising in that, firstly, it awaits for input, and, secondly, upon receiving EOF
(Ctrl-D
), doesn't produce any output.