Skip to content
Related Articles

Related Articles

Convert Text File Strings into Base64 encoding

Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 21 Apr, 2022
Improve Article
Save Article

In the Linux system, you have a command base64. This helps you to convert text into base64 encoding but how can you change multiple lines of text into base64 encoding. We will understand some common Linux command in this article. That helps us to solve our problems. We will discuss piping, echo, and how to get user input from the keyboard.



Echo Command

In Linux System, you have an echo command that printing strings and numerical values in the terminal 

echo  "Your String"



Encoding and Decoding Text

Syntax base64:

base64 options filename

Convert Text into base64 encoding

echo Team | base64



Decode base64 text into plain text

echo base64_text | base64 -d



Encoding Text File into base64 encoding

Use this Syntax:

base64 filename


Encoding Text file

Decoding base64 File into plain Text

base64 -d filename

Encoding any user Defined Text

First, we create a shell script for this task read input from users, and  convert text into base64 encoding

Use this Shell Script

#! bin/bash
echo Enter you Text
read data
output=`echo -n $data | base64` 
echo "Encoding Data $output"


Piping is reading input from one command and serving to another command. Now let’s Combine all of these commands and solve our problem. Suppose, we have a text file name of the file name.txt


$ cat names.txt
Taj Mahal
India Gate
Qutub Minar 

So we can change these strings to base64 encoding in following way:-

cat names.txt | while read names do;  echo $names | base64 ; done



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!