shell 用管道将文件的每一行传送给命令

djmepvbi  于 11个月前  发布在  Shell
关注(0)|答案(5)|浏览(95)

我有一个文本文件,每一行是一个单独的base64编码的单词。现在我想解码它。我试图使用base64命令行,但我得到的所有单词只有一行,我想每行一个。
例如,我的文件是:

Y2F0Cg==
ZG9nCg==
aG91c2UK

字符串
我想要的结果是:

dog
cat
house


但我得到了:

dogcathouse


我想xargs可以帮上忙,但我不明白。

aij0ehis

aij0ehis1#

base64 --decode与循环一起使用:

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

字符串

deyfvvtc

deyfvvtc2#

这在base64 8.13中适用:

base64 --decode test.txt

字符串
不需要拆分文件。您使用的是哪个版本?

dly7yett

dly7yett3#

你可以使用Python(不需要阅读每一行):

python -m base64 -d foo.txt

字符串

csga3l58

csga3l584#

你可以使用bash here-document <<<来实现。

cat FILE | xargs -I{} bash -c 'base64 -d <<< {}'

字符串

klh5stk1

klh5stk15#

您可以在每行后追加Cg==(base64编码的\n)。

sed 's/$/Cg==/' file.txt | base64 -d

字符串

相关问题