My input file:
Class
Number Position Range
1 Initial 50
1 Initial 50
2 Terminal 150
2 Terminal 20
2 Single 10
3 Single 20
4 Double 50
5 Initial 50
5 Initial 60
Class
Number Position Range
1 Initial 150
2 Terminal 250
2 Terminal 200
3 Single 20
4 Double 50
4 Single 100
5 Initial 100
.
.
.
My output file:
Class
Number Position Range
1 Initial 50
1 Initial 50
2 Terminal 150
2 Terminal 20
2 Single 10
3 Single 20
4 Double 50
5 Initial 50
5 Initial 60
Class
Number Position Range
1 Initial 150
2 Terminal 250
2 Terminal 200
3 Single 20
4 Double 50
4 Single 100
5 Initial 100
.
.
.
I got a long list of file. How can I added new line by using awk,sed, or perl based on the numerical number of column 1?
Each section of the content begin with "Class".
Thanks a lot for suggestion.
number=1
outputFile="/tmp/output"
for line in `cat inputFile`
do
if (`awk -F" " '{print $1}'` -eq $number )
then
echo $line >> $outputFile
else
echo "\n$line" >> $outputFile
$number++;
fi
done
#!/bin/bash
NN=""
outputFile="/tmp/output"
while read N LINE # Puts the first field (the number) in N and the rest in LINE
do
[ "$NN" != "$N" ] && echo # insert newline if the N is different than the previous value
# the && executes the next command if the return of the previous one returned TRUE
# the "!" negates the "=" and "[ ... ]" means "test if"
echo "$N $LINE"
NN=$N
done < $inputfile > $outputfile