Awk prefix/suffix help

So far I've got the following :

(1) Input

...
....
item: value
item: value
....
....

Open in new window


(2) Awk so far

awk '{if($1=="item:") printf "%s,",$2}'


But I have two problems :

(1) I do not want the last item to have a comma suffix.  I would like a closing brace, i.e. "}"

(2) I would like the line to have a prefix.....

So my desired result is sometthing like :

my prefix "misc" {value,value}
LVL 1
TwentyFourSevenAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
woolmilkporcConnect With a Mentor Commented:
awk -v I="item" '$1~I":" {if(F!="Y") {F="Y"; printf "my prefix \"" I "\" {"}; printf "%s,",$2}' inputfile | sed "s/,$/}/"

wmp
0
 
TwentyFourSevenAuthor Commented:
You are a genius.
0
All Courses

From novice to tech pro — start learning today.