Extract lines from a text file based on a parameter to a single line

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Extract lines from a text file based on a parameter to a single line

david
I'm quite new to scripting so I appreciate any help. I have a text file that in some cases can be quite long, each section of text lines can be around 6/7 lines long. It is a logfile and each section starts with the word timestamp. There is a blank line between each section of lines. Each section line ends with a semi-colon.

timestamp=201706291035.....;
line 2;
line 3;
line 4;
line 5;
line 6;
line 7;

timestamp=201706291038.....;
line 2;
line 3;
line 4;
line 5;
line 6;

I need to be able to extract each section out to another text file in a single line. Preferably without the last semi-colon.

timestamp=201706291035.....;line 2;line 3;line 4;line 5;line 6;line 7
timestamp=201706291038.....;line 2;line 3;line 4;line 5;line 6

Is that enough information for a solution?
Reply | Threaded
Open this post in threaded view
|

Re: Extract lines from a text file based on a parameter to a single line

Guru
Administrator
awk '{printf "%s",$0}/^$/{print;}END{print}' file
Reply | Threaded
Open this post in threaded view
|

Re: Extract lines from a text file based on a parameter to a single line

Raj Kiran
This post was updated on .
In reply to this post by david
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Extract lines from a text file based on a parameter to a single line

Raj Kiran
you can modify your log generator accordingly so that things will be done in one go and there will not be any need for custom scripts