Have:
An input file which contains a 1, 2, or 3 in column 1 of each line.
Want:
Three output files such that ...
output file #1 contains all input lines with a 1 in column 1.
output file #2 contains all input lines with a 2 in column 1.
output file #3 contains all input lines with a 3 in column 1.
This code
doesn't work.
Code:
# File Identifiers
InFile='/home/daniel/Desktop/Voters/dbm262inp.txt'
OutFile1='/home/daniel/Desktop/Voters/dbm262o1.txt'
OutFile2='/home/daniel/Desktop/Voters/dbm262o2.txt'
OutFile3='/home/daniel/Desktop/Voters/dbm262o3.txt'
for (( i=1; i<=3; i++ ))
do
OutFile="OutFile"$i
grep '^$i ' $InFile > $OutFile
done
Please correct the bash if you can.
A secondary issue: Even if this code worked, it reads the input file three times. Can it be made more efficient by making only one pass? awk?
Daniel B. Martin