The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing end of line to merge multiple lines tink Shell Programming and Scripting 4 10-14-2008 02:28 PM
Merge lines into one anypager Shell Programming and Scripting 7 05-22-2008 03:20 PM
merge 2 files (without repeating any lines) bluemoon1 Shell Programming and Scripting 9 10-25-2007 10:31 PM
Use sed to merge multiple lines xb88 Shell Programming and Scripting 3 08-08-2006 01:54 PM
Merge wrapped lines braindrain Shell Programming and Scripting 1 07-25-2005 07:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-17-2008
missyou missyou is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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 (permalink)  
Old 12-17-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
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 (permalink)  
Old 12-17-2008
summer_cherry summer_cherry is online now Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
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 (permalink)  
Old 12-18-2008
missyou missyou is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
Can do one more? To write into a output file

Hi,

Can help me more? to write the result into a output file. Thanks
Closed Thread

Bookmarks

Tags
merge

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0