VOOZH about

URL: https://www.geeksforgeeks.org/linux-unix/convert-text-file-strings-into-base64-encoding/

⇱ Convert Text File Strings into Base64 encoding - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert Text File Strings into Base64 encoding

Last Updated : 23 Jul, 2025

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.

Example:

👁 Image
 

Echo Command

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

echo "Your String"

Example:

👁 Image
 

Encoding and Decoding Text

Syntax base64:

base64 options filename

Convert Text into base64 encoding

echo Team | base64

Output

👁 Image
 

Decode base64 text into plain text

echo base64_text | base64 -d

Output:

👁 Image
 

Encoding Text File into base64 encoding

Use this Syntax:

base64 filename

Output:

👁 Image
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

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

Example:

$ cat names.txt
Ahmedabad
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

Output:

👁 Image
 
Comment

Explore