Solved

Awk prefix/suffix help

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now