Solved

Awk prefix/suffix help

Posted on 2011-02-24
2
812 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help With Shell Script Centos 6 6 70
SonarQube on Linux vs Windows 3 53
Ubuntu Apache Webserver - File Permissions 5 59
awk to variable in bash 2 76
Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
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é.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

828 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