Linux Tips and Tricks

Saturday, May 13, 2006

How to read a file line by line in bash scripting?

This script reads demonstrate how to read a file line by line.

#!/bin/bash

FILE=$1

# Redirect the contents of the file to stdin. This line can be removed if the lines will be piped to this script.
exec<$FILE

read line
while [[ "$line" != "" ]]
do
# Process the line here
#
done

0 Comments:

Post a Comment

<< Home