shell脚本中的base 64解码 [英] base 64 decoding in shell scripting

查看:407
本文介绍了shell脚本中的base 64解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个如下文件.

For Example I have a file like as follows .

A,Y29tLz9hPTQ2JmM9NDQzNzgmczE9Q0,123  
B,FJNLTA2MjQyMDE3LVAmczI9ODQ3MDA,321

我要打印field1,field2(通过base 64解码),field3

I want to print field1,field2(by base 64 decoding),field3

需要输出::

A,result of base 64 decode,123
B,result of base 64 decode,321

推荐答案

您可以在bash脚本中使用一些read命令和base64 -D:

You can do this in a bash script with a few read commands and base64 -D:

#!/bin/bash

while read -r line
do
  IFS=',' read -r c1 c2 c3 <<< "$line"
  data="$(base64 -D <<< "$c2")"
  echo "$c1,$data,$c3"
done < "inputfile.txt"

您的一个base64字符串中虽然包含二进制数据,但由于控制字符,输出看起来可能很时髦.

Your one base64 strings has binary data in it though, so output may look funky due to control characters.

A,com/?a=46&c=44378&s1=,123
���KL
  �
�,321T  �̏N

这篇关于shell脚本中的base 64解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆