Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 834
  • Last Modified:

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}
0
TwentyFourSeven
Asked:
TwentyFourSeven
1 Solution
 
woolmilkporcCommented:
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now