#!/bin/bash
filename=""
do_write=0
while read line
do
case $line in
==*Result*) do_write=1
;;
==*Test*) do_write=0
filename=""
;;
Name*) [[ $do_write == 0 ]] && filename=${line#Name }.txt
;;
"") # Skip blank lines
;;
*) [[ $do_write == 1 ]] && echo "$line" >> $filename
esac
done
Com seu arquivo de entrada:
$ head -10 input
====== 20160606:034441 ====== Mango(Test)
TestName MangoT
Row 0
Season N
Name Safeda
Location Delhi
====== 20160606:034441 ====== Mango(Result)
TestName MangoR
Result 0
Recebemos os resultados:
$ ./parse < input
$ ls
Alphonso.txt input parse Safeda.txt
$ head Alphonso.txt
TestName MangoR
Result 0
No_of_Mango 13
Quantity 5
Quantity 3
Quantity 1
Quantity 0
Quantity 7
Quantity 8
Quantity 70
$ head Safeda.txt
TestName MangoR
Result 0
No_of_Mango 13
Quantity 2
Quantity 3
Quantity 6
Quantity 0
Quantity 1
Quantity 9
Quantity 54