cyber
my name defines me
The following program takes a file (here it is test1.txt) and creates a new file selected .txt which contains the names and marks of students who scored less than 90. This program works for any number of lines in the text file.To make it simple this program is executed from the same directory where test1.txt is and selected.txt is also created in the same directory
test1.txt contains,
jose 50
alan 60
john 90
shaman 80
echo "NAME MARKS" > selected.txt
x=1
for line in `cat test1.txt`
do
if [ $x -eq 1 ]
then
name=$line
elif [ $x -eq 2 ]
then
marks=$line
x=0
if [ $marks -lt 90 ]
then
echo "$name $marks" >> selected.txt
fi
fi
x=`expr $x + 1`
done
is there a better way to write the same program?
test1.txt contains,
jose 50
alan 60
john 90
shaman 80
echo "NAME MARKS" > selected.txt
x=1
for line in `cat test1.txt`
do
if [ $x -eq 1 ]
then
name=$line
elif [ $x -eq 2 ]
then
marks=$line
x=0
if [ $marks -lt 90 ]
then
echo "$name $marks" >> selected.txt
fi
fi
x=`expr $x + 1`
done
is there a better way to write the same program?