How to merge multiline into line begining with specific word


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to merge multiline into line begining with specific word
# 1  
Old 10-14-2008
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  
Old 10-14-2008
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  
Old 10-14-2008
perl:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed / awk to get specific word in line

I have http log that I want to get words after specific "tag", this a sample line from the log: 98,POST,200 OK,www.facebook.com,Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1,/ajax/updatestatus.php?__a=1,datr=P_H1TgjTczCHxiGwdIF5tvpC; lu=Si1fMkcrU2SInpY8tk_7tAnw;... (6 Replies)
Discussion started by: erlanq
6 Replies

2. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

3. Shell Programming and Scripting

break the string and print it in a new line after a specific word

Hi Gurus I am new to this forum.. I am using HP Unix OS. I have one single string in input file as shown below Abc123 | cde | fgh | ghik| lmno | Abc456 |one |two |three | four | Abc789 | five | Six | seven | eight | Abc098 | ........ I want to achive the result in a output file as shown... (3 Replies)
Discussion started by: kannansr621
3 Replies

4. Shell Programming and Scripting

catch a particular word from a specific line -perlscript

Hi, App.log contains the data- ================================================= Value of DsRef =null Recovery File exixts Recovered readFile 20110509 17:00:00.369019 +0100s The DsRef Recovered from Recovery.txt file : 20110509 17:00:00.369019 +0100 Recovered from Recovery.txt file... (2 Replies)
Discussion started by: pspriyanka
2 Replies

5. UNIX for Advanced & Expert Users

Count specific word or character per line

Hi, I need help regarding counting specific word or character per line and validate it against a specific number i.e 10. And if number of character equals the specific number then that line will be part of the output. Specific number = 6 Specific word or char = || Sample data:... (1 Reply)
Discussion started by: janzper
1 Replies

6. Shell Programming and Scripting

how to Add word at specific location in line

eg . i have file x.txt contains : java coding , shell scriptting etc... now i want to add "is langauge" after word java. output should be java is langauge coding , shell scriptting etc... any idea how to use shell script to do it ? (10 Replies)
Discussion started by: crackthehit007
10 Replies

7. Shell Programming and Scripting

Merge multiline into Singleline

Hi, I'm newbie in this forum and I already searched regarding Merge multiline into singleline but I always found different result which is I don't want it like i want. Here is the data that i have it: *** ALARM 711 A1/BTS "MAD08B1 08ACPA0"U 090604 1040 RADIO X-CEIVER ADMINISTRATION BTS... (5 Replies)
Discussion started by: inteliduy
5 Replies

8. Shell Programming and Scripting

merge columns into one line after a specific pattern

Hi all, im a linux newbie, plz help! I have a file - box -------- Fox-2 -------- UF29 zip42 -------- zf-CW SNF2_N Heli_Z -------- Fox -------- Kel_1 box (3 Replies)
Discussion started by: sam_2921
3 Replies

9. Shell Programming and Scripting

move the last word to begining of next line - SED

Hello, I'm trying to move the last word of matching pattern to the begining of next line. Appreciate if anyone post the script. From the below line I'm getting the last word, Note: this word also appears in many places in my file #return the last word of line that contains ListenPort sed... (4 Replies)
Discussion started by: baskar
4 Replies

10. Shell Programming and Scripting

grep a word from a specific line

for example: searches only for single word for single word this is line three match=$(grep -n -e "single" data.txt) this command will stored "..... single ...... single" into search. how can i grep the single word just from line 2 only?? (3 Replies)
Discussion started by: blurboy
3 Replies
Login or Register to Ask a Question