The UNIX and Linux Forums  


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
delete blank space in begining of line karthikn7974 Shell Programming and Scripting 4 05-07-2008 05:40 AM
move the last word to begining of next line - SED baskar Shell Programming and Scripting 4 02-15-2008 12:28 PM
Can "sed" substitute word on a specific line? minifish Shell Programming and Scripting 2 02-14-2008 05:25 PM
grep a word from a specific line blurboy Shell Programming and Scripting 3 01-23-2008 04:13 AM
transforming a multiline record to single line anju Shell Programming and Scripting 9 01-14-2008 07:55 AM

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 10-14-2008
missyou missyou is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
How to merge multiline into line begining with specific word

Hi,

The file format is like the following.
timestamp=2008-02-28-23.50.29.550675;category=CONTEXT;audit event=CONNECT;
event correlator=2;
database=CURDOMS;userid=inst3;authid=INST3;
origin node=0;coordinator node=0;
application id=AC122081.FA97.054468155029;application name=java;

timestamp=2008-02-28-23.50.29.552161;category=CONTEXT;audit event=ROLLBACK;
event correlator=2;
database=CURDOMS;userid=inst3;authid=INST3;
origin node=0;coordinator node=0;
application id=AC122081.DA97.054468153551;application name=java;

timestamp=2008-02-28-23.50.29.552183;category=CONTEXT;audit event=ROLLBACK;
event correlator=2;
database=CURDOMS;userid=inst3;authid=INST3;
origin node=0;coordinator node=0;
application id=AC122081.DA97.054468153551;application name=java;

timestamp=2008-02-28-23.50.29.552188;category=CONTEXT;audit event=CONNECT_RESET;
event correlator=3;
database=CURDOMS;userid=inst3;authid=INST3;
origin node=0;coordinator node=0;
application id=AC122081.DA97.054468153551;application name=java;

timestamp=2008-02-28-23.50.29.557734;category=CONTEXT;audit event=CONNECT;
event correlator=2;
database=CURDOMS;userid=inst3;authid=INST3;
origin node=0;coordinator node=0;
application id=AC122081.FB97.054468155031;application name=java;

I would like to merge the lines between the "timestamp" to the next "timestamp" into one line. Can someone help me?



Thanks
Missyou
  #2 (permalink)  
Old 10-14-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,886
cat file | while read line ; do case $line in timestamp*) echo "$line" ;; "") echo "$oneline"; echo ;; *) oneline="$oneline""$line" ;; esac done
-->
Code:
cat file | while read line ; do
   case $line in 
    timestamp*)  echo "$line" ;;
    "") echo "$oneline"; echo ;;
    *) oneline="$oneline""$line" ;;
   esac
done
        
There will also be solutions via awk and sed and perl.
  #3 (permalink)  
Old 10-14-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,089
perl:

open FH,"<b"; undef $/; $str=<FH>; $str=~ tr/\n/ /; $str=~ s/timestamp/\ntimestamp/g; print $str; close FH;
-->
Code:
open FH,"<b";
undef $/;
$str=<FH>;
$str=~ tr/\n/ /;
$str=~ s/timestamp/\ntimestamp/g;
print $str;
close FH;
        
Closed Thread

Bookmarks

Tags
timestamp multiline

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 07:29 AM.


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