SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks

Friday, April 16, 2010

Linux Bash script – How to read a linux file – script


Here is the sample script to how how to read an unix or linux file using shell script:
First Method – Assumption mydatafile.txt exists in the same directory:
#!/bin/sh
FILENAME="mydatafile.txt"
while read line
do
echo $line
done < $FILENAME
Second Method – Assumption mydatafile.txt exists in the same directory:
#!/bin/sh
FILENAME="mydatafile.txt"
LN=0
cat $FILENAME ‘ while read FILE_NAME
do
LN=$(($LN + 1))
echo "Line $LN=$FILE_NAME"
done

No comments:

Post a Comment