UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old March 2nd, 2004, 04:11 AM
pavithra123 pavithra123 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 pavithra123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool Format Data - Into One Line

Hi All,

I have data like below in a file

2004-01-01:01:00:00.00
339462,107461
2004-01-01:02:00:00.00
202765,72707


I need to format and get it something like this

2004-01-01:01:00:00.00 339462,107461
2004-01-01:02:00:00.00 202765,72707.

I tried using some options with SED/AWK but i did not get the desired result.

Any help is greatly appreciated.

Best Regards
Prem.

Reply With Quote
  #2  
Old March 2nd, 2004, 12:05 PM
druuna druuna is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 137 druuna User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 37 sec
Reputation Power: 0
You could use sed to solve this problem (there are probably other ways too).
This example only works if all date lines start with 2004, but you can change/expand this.

Content sed file (join-2-lines.sed):
/^2004/{
N
s/\n/ /
}

$ sed -f join-2-lines.sed <infile>

Or from within a (shell) script:
#!/bin/bash

sed '/^2004/{
N
s/\n/ /
}' <infile>

Short explanation:

Sed looks for lines starting with 2004 (/^2004/) and, if found, puts it in its 'pattern space'. The N tells sed to read the next line and append this to the pattern space (it does add a newline between the 2 lines).
The s/\n/ / part substitutes the newline (\n) with a space. This substitution is done to the content of the pattern space, so you are left with 1 complete line.
Next, sed will print the line to standard out, and starts looking for the next line that starts with 2004.

Hope this helps.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Format Data - Into One Line


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway