Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-10-2012
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Script for data manipulation

Hi all!

my first post here, so mods -- if this should ideally be in the scripts section, please move there. Thanks!

I have data in the following format:

Code:
key1:value1 key2:value2 key3:value3
A
B
C
D
key1:value4 key2:value5 key3:value6
A1
B1
key1: ...

and so on

I want an output of the following form

Code:
value3, A B C D
value6, A1 B1

and so on [basically, get value of key3 and rearrange the data on one line with a space separating each "word".

Can someone tell me how to do this, and show it with a script?

Thank you.

Last edited by fpmurphy; 06-11-2012 at 01:23 AM..
Sponsored Links
    #2  
Old 06-10-2012
bartus11's Avatar
Registered User
 
Join Date: Apr 2009
Posts: 3,145
Thanks: 3
Thanked 957 Times in 936 Posts
Try:
Code:
awk '/key3/{split($3,a,":");printf "\n"a[2]", "}!/key3/{printf $0" "}END{printf "\n"}' file

The Following User Says Thank You to bartus11 For This Useful Post:
gnat01 (06-11-2012)
Sponsored Links
    #3  
Old 06-11-2012
Registered User
 
Join Date: Jun 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks, bartus11! Worked perfectly
Sponsored Links
Closed Thread

Tags
data, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Data manipulation from one file vaibhavkorde Shell Programming and Scripting 3 03-14-2011 03:16 AM
Data Manipulation khestoi UNIX for Dummies Questions & Answers 11 02-02-2010 06:29 PM
Data manipulation with Awk Cham Shell Programming and Scripting 13 08-29-2009 08:07 AM
Data manipulation in perl chriss_58 Shell Programming and Scripting 1 06-13-2008 01:56 PM
data manipulation script grinder182533 UNIX for Dummies Questions & Answers 1 11-10-2006 01:48 PM



All times are GMT -4. The time now is 10:18 PM.