HowTech

Watch & learn the new technologies!
  • Home
  • Basics
  • Internet
  • Security
  • Audio
  • Video
  • Graphics
  • Tweaks
  • About
« How to Write Bash Sleep Script
How to Use Conditions in Bash Scripting (Bash IF Script) »

How to Read a File Line by Line in Bash

In this tutorial we will show you how to write a bash script which will read this text file over here, that is let the bash read it line by line.
This file that is read by bash is then displayed as the output where you previously entered your command.
To learn how to let bash read from a file follow the steps given in the tutorial below.



Step 1 – Specify variables
We will start the while loop and after that we will specify three variables over here as “first”, “second” and “third”. The space between the variables will tell the compiler that the new line has started.
while read FIRST SECOND THIRD
Enter variables

Step 2 – Print variable
After that we will simply print the three variables and for that we will use the echo command and a dollar sign before each variable.
do
echo “————-“
echo “$FIRST”
echo “$SECOND”
echo “$THIRD”
Make the variables show in output

Step 3 – Specify the name
At the end, we will specify the file name from which the data has to be extracted, and through this we will let bash read from a file and provide us with the output of whatever it extracts.
done < textfile
Set the name

Step 4 – Let the bash scrip read the data
And over here, you can see that the bash script is reading the data from the file, line by line and since we have initiated a while loop in the beginning, the loop will continue till it has reached the last line.
And that’s it, by following these steps you can learn and understand how to let bash read a file line by line in Linux.
Let the loop continue till it reached the end

Related posts:

  1. How to Read Excel File Java
  2. How to Zip a File in Windows
  3. How to Change File Extension in Windows
  4. How to Use Conditions in Bash Scripting (Bash IF Script)
Posted on June 20, 2013 by XZoLMLRU2Pg. This entry was posted in PC and tagged Bash, file, Line by Line, read. Bookmark the permalink.
« How to Write Bash Sleep Script
How to Use Conditions in Bash Scripting (Bash IF Script) »
  • Categories

    • Audio
    • Basics
    • Graphics
    • LifeStyle
    • Mac
    • Mobile
    • Network Security
    • Office
    • PC
    • Tweaks
    • Video
    • Web
  • add Adobe change convert create delete download Ebay Effect email Excel facebook GIMP gmail google how to image install ios ios9 iPad iPhone iPhone apps Lightroom mac make Microsoft Access online online service outlook Photoshop Photoshop CS6 powerpoint search set text Twitter use video windows Windows 7 Windows 8 Word WordPress youtube

  • Useful links

    • Privacy Policy
    • Terms and Conditions
  • Home
  • Basics
  • Internet
  • Security
  • Audio
  • Video
  • Graphics
  • Tweaks
  • About

Proudly powered by WordPress