5

I have a file which is encoded by base64:

5byg5bCP5piO
c2FyYWg=
5p2O56OK

I want to decode it line by line:

:%!base64 -d

But I get everything in one line:

张小明sarah李磊

What I want is:

张小明
sarah
李磊

How can I do it?

2 Answers 2

4

Another solution is the following, which works nicely for me.

%g/^/.!base64 -d
2
  • 2
    :g/./.!base64 -d
    – kev
    Dec 19, 2011 at 7:07
  • vimgolfist? ;-) Yeah, the % is in case of :g redundant. Also the . regexp makes sense - no use to try to decode empty lines.
    – Martian
    Dec 19, 2011 at 12:36
4
:%normal !!base64 -d^M

:{range}norm[al][!] {commands}                          *:normal-range*
                        Execute Normal mode commands {commands} for each line
                        in the {range}.  Before executing the {commands}, the
                        cursor is positioned in the first column of the range,
                        for each line.  Otherwise it's the same as the
                        ":normal" command without a range.
                        {not in Vi}
                        Not available when |+ex_extra| feature was disabled at
                        compile time.

Yet another way:

sed 's/$/Cg==/' | base64 -d
1
  • On mac os, I had to use -D option. -d didn't work.
    – user674669
    Mar 6, 2018 at 7:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .