LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-01-2015, 12:20 AM   #1
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Rep: Reputation: 0
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.

Last edited by maddyfreaks; 10-01-2015 at 12:22 AM.
 
Old 10-01-2015, 12:23 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
Old 10-01-2015, 12:28 AM   #3
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
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.
 
Old 10-01-2015, 01:07 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Also, where is your attempt at solving this problem?
 
Old 10-01-2015, 02:51 AM   #5
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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
 
Old 10-02-2015, 09:01 PM   #6
maddyfreaks
Member
 
Registered: May 2011
Posts: 85

Original Poster
Rep: Reputation: 0
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.

Last edited by maddyfreaks; 10-02-2015 at 09:06 PM.
 
Old 10-03-2015, 01:53 AM   #7
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split single line into multiple lines with 3 column each udiubu Programming 7 11-26-2017 09:41 AM
Linux Command - split single line into multiple lines ALEXTANG Linux - General 1 09-16-2014 01:19 PM
Linux Command - split single line into multiple lines ALEXTANG Linux - General 1 09-16-2014 09:17 AM
Break single line into multiple lines based on a pattern raja219 Linux - Newbie 3 02-20-2013 12:44 AM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 02:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration