Scripts‎ > ‎

Read lines one by one from a file

Notes:-

1. This script can be used to read files line by line, which is not possible with "for loop" when there are lines with spaces.
2. This script assumes that file name is filename

##############################################################
#!/bin/bash
COUNT=`wc -l filename| awk '{print $1}'`
NUM=1;

while [ $NUM -le $COUNT ]
do
TEMP=`awk "NR==$NUM" filename`;
echo "$TEMP";
NUM=$(($NUM+1));
done

##############################################################
Comments