Read a file line by line

This code demonstrates how to read a file line by line for processing. In this example, we have a simple file sample.txt

$ cat sample.txt
Python C++ Ruby Java Hack

The code below reads the sample.txt file in the current directory and prints out each individual line.

#!/bin/bash

# define input file
input="./sample.txt"
while IFS= read -r line
do
  
  # Printing each line  
  echo "$line" 

done < "$input" 
Python C++ Ruby Java Hack