shellcommand-linebase64xargs

pipe each line of a file to a command


I have a text file which each line is a one word coded base64 separely. Now I want to decode it. I'm trying to use base64 command line, but I'm getting all the words in only one line, I want one per line.

For example, my file is:

Y2F0Cg==
ZG9nCg==
aG91c2UK

I want as result:

dog
cat
house

But I'm getting:

dogcathouse

I think xargs could help, but I'm not getting the point.


Solution

  • Use base64 --decode together with a loop:

    $ while IFS= read -r line; do echo "$line" | base64 --decode; done < file
    cat
    dog
    house