|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. ![]() |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Format Data - Into One Line |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|