merge multi-lines into one line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting merge multi-lines into one line
# 1  
Old 12-17-2008
merge multi-lines into one line

Hi,

Can anyone help me for merge the following multi-line logs( the black lines) which beginning with time: into one line. For the line with "-", it needs to be deleted. Please see the red color line.

#########################################
time: 20080817073334
dn: uid=ok,ou=nbt users,cn=998,dc=tcb,dc=com
changetype: modify
replace: NBTSignOn
NBTSignOn: 20080817 172.31.4.81 998A
-
replace: modifiersName
modifiersName: uid=ok,ou=nbt users,cn=998,dc=tcb,dc=com
-
replace: modifyTimestamp
modifyTimestamp: 20080816233336Z
-
-->
time: 20080817073334 dn: uid=ok,ou=nbt users,cn=998,dc=tcb,dc=com changetype: modify replace: NBTSignOn NBTSignOn: 20080817 172.31.4.81 998A replace: modifiersName modifiersName: uid=ok,ou=nbt users,cn=998,dc=tcb,dc=com replace: modifyTimestamp modifyTimestamp: 20080816233336Z

time: 20080817074803
dn: uid=on,ou=nbt users,cn=009,dc=tcb,dc=com
changetype: modify
replace: NBTSignOn
NBTSignOn: 20080817 172.16.8.82 009G
-
replace: modifiersName
modifiersName: uid=on,ou=nbt users,cn=009,dc=tcb,dc=com
-
replace: modifyTimestamp
modifyTimestamp: 20080816234805Z

--> time: 20080817074803 dn: uid=on,ou=nbt users,cn=009,dc=tcb,dc=com changetype: modify replace: NBTSignOn NBTSignOn: 20080817 172.16.8.82 009G replace: modifiersName modifiersName: uid=on,ou=nbt users,cn=009,dc=tcb,dc=com replace: modifyTimestamp modifyTimestamp: 20080816234805Z
# 2  
Old 12-17-2008
Assuming all logical records end with modifyTimestamp:
(use nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk '!/^-/ { 
  r = r ? r FS $0 : $0 
  }
/^modifyTimestamp/ {
  print r; r = ""
  }' infile

# 3  
Old 12-17-2008
Code:
#! /usr/bin/perl
open FH,"<a.txt";
undef $/;
my @arr=split("\n",<FH>);
$str=join " ",grep {m/[^-]/} @arr;
$str=~s/ time/\ntime/;
print $str,"\n";

# 4  
Old 12-18-2008
Can do one more? To write into a output file

Hi,

Can help me more? to write the result into a output file. ThanksSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Merge multi-lines into one single line using shell script or Linux command

Hi, Can anyone help me for merge the following multi-line log which beginning with a " and line ending with ": into one line. *****Original Log***** 087;2008-12-06;084403;"mc;;SYHLR6AP1D\LNZW;AD-703;1;12475;SYHLR6AP1B;1.1.1.1;0000000062;HGPDI:MSISDN=12345678,APNID=1,EQOSID=365;... (3 Replies)
Discussion started by: rajeshlinux2010
3 Replies

2. UNIX for Advanced & Expert Users

Merge files with multi-line stanzas

Hello. I try to merge few /etc/qconfig files in AIX (from few servers into one file on new server). Could you please help me what would be the best way to merge files that contain multi-line stanzas, like this: stanza1: attr1 = value1 attr2 = value2 attr3 = value3 stanza2: attr1 =... (7 Replies)
Discussion started by: kareem33
7 Replies

3. UNIX for Dummies Questions & Answers

How to merge every n lines into one line?

I want to merge every 16 lines into one line, how can I do that? My file looks like below: 0 . 2 2 . 0 0 . 0 0 . 0 0 . 0 0 0 0 0 (2 Replies)
Discussion started by: ml4me
2 Replies

4. Shell Programming and Scripting

Merge multiple lines to one line when line starts with and ends with

example: comment Now_TB.table column errac is for error messages 1 - first 2 - second 3 -third ; in this example I need to be able to grab the comment as first word and ; as the last word and it might span a few lines. I need it to be put all in one line without line breaks so I can... (4 Replies)
Discussion started by: wambli
4 Replies

5. Shell Programming and Scripting

replacing multi lines with 1 line

I have an xml file that is stripped down to output that looks bacically like; <!-- TABLEA header --> <tablea> some fields </tablea> <!-- TABLEB header --> <!-- TABLEC header --> <tablec> some fields </tablec> I want to remove the header... (3 Replies)
Discussion started by: Griffs_Revenge
3 Replies

6. Shell Programming and Scripting

Multi lines to single line

HI, My input file contains the data as like below: A1234119993 B6271113 Bghjkjk A1234119992 B6271113hi Bghjkjkmkl the output i require is : A1234119993 B6271113 Bghjkjk A1234119992 B6271113hi Bghjkjkmkl Please help me in this. Thanks (6 Replies)
Discussion started by: pandeesh
6 Replies

7. Shell Programming and Scripting

Merge multi-line output into a single line

Hello I did do a search and the past threads doesn't really solve my issue. (using various awk commands) I need to combine the output from java -version into 1 line, but I am having difficulties. When you exec java -version, you get: java version "1.5.0_06" Java(TM) 2 Runtime... (5 Replies)
Discussion started by: flagman5
5 Replies

8. Shell Programming and Scripting

Help on Merge multi-lines into one single line

Hello, Can anyone let me know how to use Perl script to Merge following multi-lines into one single line... ***** Multi-line***** FILE_Write root OK Tue Jul 01 00:00:00 2008 cl_get_path file descriptor = 1 FILE_Write root OK ... (5 Replies)
Discussion started by: happyday
5 Replies

9. Shell Programming and Scripting

How to use Perl to merge multi-line into single line

Hi, Can anyone know how to use perl to merge the following multi-line information which beginning with "BAM" into one line. For each line need to delete the return and add a space. Please see the red color line. ******Org. Multi-line) BAM admin 101.203.57.22 ... (3 Replies)
Discussion started by: happyday
3 Replies

10. Shell Programming and Scripting

Merge multi-lines into one single line

Hi, Can anyone help me for merge the following multi-line log which beginning with a number and time: into one line. For each line need to delete the return and add a space. Please see the red color line. *****Original Log*****... (4 Replies)
Discussion started by: happyday
4 Replies
Login or Register to Ask a Question