简体   繁体   English

如何在Linux中解码base64编码的行?

[英]How do I decode base64 encoded lines in linux?

I am trying to read a file & extract only the base64 encoded part. 我正在尝试读取文件并仅提取base64编码的部分。 I am doing so by using sed to find the lines between the pattern's 'base64' & '--'. 我这样做是通过使用sed查找模式的'base64'和'-'之间的线。

I am able to do so using 我可以使用

 sed -e '1,/base64/d' -e '/--/,$d' file.txt | sed '/^\s*$/d'

But when i try to decode it using base64 as shown below, 但是,当我尝试使用base64对其进行解码时,如下所示,

 sed -e '1,/base64/d' -e '/--/,$d' file.txt | sed '/^\s*$/d' | base64 -d

I get an error message as :- 我收到如下错误消息:

BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:Microsoft Exchangbase64: invalid input

Please let me know what am i doing wrong and is there an alternate, better way to achieve the end result. 请让我知道我在做错什么,还有另一种更好的方法可以达到最终结果。 Any help is appreciated. 任何帮助表示赞赏。

I got the issue. 我知道了 the lines in the files were as follows 文件中的行如下

QkVHSU46VkNBTEVOREFSDQpNRVRIT0Q6UkVRVUVTVA0KUFJPRElEOk1pY3Jvc29mdCBFeGNoYW5nZSBTZ
XJ2ZXIgMjAxMA0KVkVSU0lPTjoyLjANCkJFR0lOOlZUSU1FWk9ORQ0KVFpJRDpBVVMgRWFzdGVybiBTdG 

There was an end line character at the end, so all i had to do was remove it. 最后有一个结束行字符,所以我要做的就是删除它。 Hence, now my code looks as below & it works :- 因此,现在我的代码如下所示,并且可以正常工作:-

sed -e '1,/base64/d' -e '/--/,$d' _12829640_21.12.-.5p.meeting.room_1485234639532_1.mail | sed '/^\s$/d' | tr -d "\n\r"  | base64 -d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM