I have a file to process and get some entries from it. The file format is:
String1:"Hello" String2:"World" String3:"Question" End String1:"HelloAgain" String5:"Answer" End String1:"NewEntry" String2:"Foo" String5:"NewFile" End
Script will iterate and try to find String1 and print it, if String2 also present in that block append it to String1 and print.
Hello World HelloAgain NewEntry Foo
I need to loop through every such block.What I mean by a block here is content between every "End" string. I have a script like:
cat $1 | while read line do if [[ $line == "String1="* ]]; then string1=$line fi if [[ $line == "String2="* ]]; then string2=$line fi if [[ $line == "End" ]]; then if [ $string1 ]; then echo "string1/"$string1" fi if [ $string1 ] && [ $string2 ]; then echo $string1" "$string2 fi #Reset values string1='' string2='' fi done
This code works fine but the processing in between these blocks can become more complex, whats the best way to iterate such blocks and process those block entries.
NOTE:The file is kind of a property file.