1. Home
  2. Bash
  3. Examples
  4. Read file line by line?

Shell Script to Read File

Brief: This example will help you to read a file in a bash script. This tutorial contains two methods to read a file line by line using a shell script.

Method 1 – Using simple loop

You can use while read loop to read a file content line by line and store into a variable.

Note – In above script line is a variable only. You can use any variable name in place of the line of your choice.

Method 2 – Using IFS

The IFS (Internal Field Separator) is a special shell variable used for splitting words and line based on its value. The default value is .

Tags , ,
Was this article helpful to you? Yes 1 No