LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Merge Lines into Single line (https://www.linuxquestions.org/questions/linux-newbie-8/merge-lines-into-single-line-4175554965/)

maddyfreaks 10-01-2015 12:20 AM

Merge Lines into Single line
 
Hi

I need help in merging lines

Currently this is what i have a file with below output.

REPLICAT REP01 Last Started 2015-09-29 11:02 Status RUNNING
INTEGRATED
Checkpoint Lag 00:00:00 (updated 00:00:07 ago)
Process ID 7315
Log Read Checkpoint File ./dirdat/t1000274
2015-09-30 21:13:26.027860 RBA 10581838



Process ID 22834
Log Read Checkpoint File ./dirdat/t3000001
2015-09-30 21:10:01.191599 RBA 28232246

--Finally i need like below.

Code:

REPLICAT  REP01    Last Started 2015-09-29 11:02  Status RUNNING INTEGRATED Checkpoint Lag      00:00:00 (updated 00:00:07 ago) Log Read Checkpoint  File ./dirdat/t1000274  2015-09-30 21:13:26.027860  RBA 10581838
REPLICAT  REP03    Last Started 2015-09-22 21:09  Status RUNNING              Checkpoint Lag      00:00:00 (updated 00:00:04 ago) Log Read Checkpoint  File ./dirdat/t3000001 2015-09-30 21:10:01.191599  RBA 28232246

Please help me.

chrism01 10-01-2015 12:23 AM

Your output seems to be missing some lines that are in the input - can you redo and put both i/p and o/p recs inside CODE blocks
Thank you

Sefyir 10-01-2015 12:28 AM

Are these lines for the most part the same (same number of columns and such)?
If so, making a macro with vi(m) and recording the sequence of events for one line and repeating for all others would be fairly easy.

grail 10-01-2015 01:07 AM

Also, where is your attempt at solving this problem?

HMW 10-01-2015 02:51 AM

Yes, you can do that, in a LOT of different ways depending on how much you want to fine-tune things. But, anyway... given this infile:
Code:

REPLICAT REP01 Last Started 2015-09-29 11:02 Status RUNNING
INTEGRATED
Checkpoint Lag 00:00:00 (updated 00:00:07 ago)
Process ID 7315
Log Read Checkpoint File ./dirdat/t1000274
2015-09-30 21:13:26.027860 RBA 10581838



Process ID 22834
Log Read Checkpoint File ./dirdat/t3000001
2015-09-30 21:10:01.191599 RBA 28232246

I get this result with a tiny script (no, you don't NEED to write a script - but I did):
Code:

$ cat merged.txt
REPLICAT REP01 Last Started 2015-09-29 11:02 Status RUNNING        INTEGRATED        Checkpoint Lag 00:00:00 (updated 00:00:07 ago)        Process ID 7315        Log Read Checkpoint File ./dirdat/t1000274        2015-09-30 21:13:26.027860 RBA 10581838       


Process ID 22834        Log Read Checkpoint File ./dirdat/t3000001        2015-09-30 21:10:01.191599 RBA 28232246

I have been lazy here, and replaced linebreaks with tabs. It is not clear to me whether you need to differentiate between tabs and other whitespace in your desired output or not. If you do, then you will have to fine-tune some more.

Check these out: https://lmddgtfy.net/?q=bash%20merge...o%20one%20line

Best regards,
HMW

maddyfreaks 10-02-2015 09:01 PM

Thanks mates. I need this below.

I need to wriste some script to GoldenGate...

I have a file with below info

==================================================================================================
Code:

REPLICAT  REP01  Last Started 2015-09-29 11:02  Status ABENDED
Checkpoint Lag      00:00:09 (updated 33:30:41 ago)
Log Read Checkpoint  File ./dirdat/t1000274
                    2015-10-01 12:24:46.959298  RBA 17573036
                                       
REPLICAT  REP02  Last Started 2015-09-29 21:36  Status RUNNING
Checkpoint Lag      00:00:00 (updated 00:00:08 ago)
INTEGRATED
Process ID          10109
Log Read Checkpoint  File ./dirdat/R1000131
                    2015-10-02 17:33:14.021156  RBA 11917019

==================================================================================================
from the above i need output like below.
Code:

REPLICAT  REP01  Last Started 2015-09-29 21:36  Status RUNNING            Checkpoint Lag  00:00:00 (updated 00:00:08 ago) Log Read Checkpoint  File ./dirdat/R1000131  2015-10-02 17:33:14.021156  RBA 11917019
REPLICAT  REP02  Last Started 2015-09-29 11:02  Status ABENDED INTEGRATED Checkpoint Lag  00:00:09 (updated 33:30:41 ago) Log Read Checkpoint  File ./dirdat/t1000274  2015-10-01 12:24:46.959298  RBA 17573036

Please help me.

HMW 10-03-2015 01:53 AM

Your input and output don't match.

Do you really want to switch REP01 to REP02?

If not, then see my previous post. With your (ambigous) example file, I get this output from my script:
Code:

REPLICAT REP01 Last Started 2015-09-29 11:02 Status ABENDED    Checkpoint Lag 00:00:09 (updated 33:30:41 ago)  Log Read Checkpoint File ./dirdat/t1000274      2015-10-01 12:24:46.959298 RBA 17573036
REPLICAT REP02 Last Started 2015-09-29 21:36 Status RUNNING    Checkpoint Lag 00:00:00 (updated 00:00:08 ago)  INTEGRATED      Process ID 10109        Log Read Checkpoint File ./dirdat/R1000131      2015-10-02 17:33:14.021156 RBA 11917019

But, you have to specify if you want to CHANGE the content of your example file or not. Because (again) your two examples are not equal. Therefore it is no longer the question of simply merging, but also to ALTER the content.

However, if you want to merge, check out:
Code:

man tr
Best regards,
HMW


All times are GMT -5. The time now is 07:43 PM.