Solved

Awk prefix/suffix help

Posted on 2011-02-24
2
810 Views
Last Modified: 2012-05-11
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
Comment
Question by:TwentyFourSeven
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 34968848
awk -v I="item" '$1~I":" {if(F!="Y") {F="Y"; printf "my prefix \"" I "\" {"}; printf "%s,",$2}' inputfile | sed "s/,$/}/"

wmp
0
 
LVL 1

Author Closing Comment

by:TwentyFourSeven
ID: 34968984
You are a genius.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question