Here is a great challenge for someone to attack!
Is there a way to achieve the following using sed and/or awk. Please see myfile.txt below:
$cat myfile.txt:
entry
"entry-header"
entry-top
name
!udwd870kdjll -- random string
Derek
code=nsmssdllskpdp
code=nassmdllskpdp
name
!ueo0000kdjll -- random string
name
Moss
!ueo3870kdjll -- random string
choice=Pear comments="Great"
choice=Pineapple comments="Not quite the best"
choice=Apple comments="OK"
choice=Grapes comments="OK"
choice=Grapefruit comments="OK"
/entry-top
/entry
entry
"entry-header"
entry-top
!udwd870kdjll -- random string
name
!udwd870kdjll -- random string
Sarah
code=nsmsstyyukpdp
code=nalmdllskpdpx
!ueo0000kdjll -- random string
name
Zimmerman
!ueo3870kdjll -- random string
choice=Orange comments="These are awesome"
choice=Pineapple comments="Nice"
choice=Mango comments="Pretty good"
/entry-top
/entry
etc...
This is a huge list of peoples favorite fruits, and their entries are in order, with the one at the top being the favorite. I need to be able to assign a number to each entry so I can collate the results. I also need to differentiate between the two name lines given, the surname always appeasr second. As long as I can update the labels (to be name1 and name2 rather than name and name), I will be able to manipulate the text how I want to.
The required output is below, and should show you exactly what I am after:
entry
"entry-header"
entry-top
name1
!udwd870kdjll -- random string
Derek
code=nsmssdllskpdp
name2
code=nassmdllskpdp
!ueo0000kdjll -- random string
Moss
!ueo3870kdjll -- random string
choice1=Pear comments="Great"
choice2=Pineapple comments="Not quite the best"
choice3=Apple comments="OK"
choice4=Grapes comments="OK"
choice5=Grapefruit comments="OK"
/entry-top
/entry
entry
"entry-header"
entry-top
name1
!udwd870kdjll -- random string
Sarah
code=nsmsstyyukpdp
name2
code=nalmdllskpdpx
!ueo0000kdjll -- random string
Telford
!ueo3870kdjll -- random string
choice1=Orange comments="These are awesome"
choice2=Pineapple comments="Nice"
choice3=Mango comments="Pretty good"
/entry-top
/entry