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
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
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