Published on April 1, 2017 by ProgrammingKnowledge

How do I read a text file line by line under a Linux or UNIX-like system using BASH shell?
You can use while..do..done bash loop to read file line by line on a Linux, OSX, or Unix-like system.
There are basically three ways to read file content using bash.
1a: While loop: Single line at a time: Input redirection.
1b: While loop: Single line at a time:
Open the file, read from a file descriptor (in this case file descriptor #4).
2: While loop: Read file into single variable and parse.

My Website – www.codebind.com
My Blog – goo.gl/Nd2pFn
My Facebook Page – goo.gl/eLp2cQ
Google+ – goo.gl/lvC5FX
Twitter – twitter.com/ProgrammingKnow
Pinterest – goo.gl/kCInUp
Text Case Converter – goo.gl/pVpcwL
Epoch Timestamp Converter – goo.gl/Zedjo5
Decimal – Binary – Hexadecimal Converter – goo.gl/rkX3JE
8-bit Checksum Calculator – goo.gl/inxvIT

Leave a Reply

1 Comment on "Shell Scripting Tutorial for Beginners 17 – Read a file content in Bash"

Notify of
avatar

sansaction l
Guest
sansaction l
25 days 4 hours ago

its aprli 1st, i don't trust anything

wpDiscuz