我有一个文本文件,其中每一行都是一个单独的base64编码的单词。现在我想解码它。我正在尝试使用 base64 命令行,但我只在一行中获取所有单词,我想要每行一个。
例如我的文件是:
Y2F0Cg==
ZG9nCg==
aG91c2UK
我想要的结果:
dog
cat
house
但我得到:
dogcathouse
我认为 xargs 可以提供帮助,但我没有明白这一点。
将
base64 --decode
与循环一起使用:
$ while IFS= read -r line; do echo "$line" | base64 --decode; done < file
cat
dog
house
这对我有用
base64
8.13:
base64 --decode test.txt
无需拆分文件。你用的是哪个版本?
您可以使用 Python(无需阅读每一行):
python -m base64 -d foo.txt
您可以使用 bash here-document
<<<
为此。
cat FILE | xargs -I{} bash -c 'base64 -d <<< {}'
您可以在每行后面附加
Cg==
(base64 编码 \n
)。
sed 's/$/\nCg==/' file.txt | base64 -d