Continuation lines to be glued back to original line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Continuation lines to be glued back to original line
# 1  
Old 08-03-2017
Continuation lines to be glued back to original line

I am parsing a log with this format:

Code:
06:36:12.230 [TASK1] details here
06:36:12.250 [TASK1] details here
06:36:12.260 [TASK1] details here
continuation here
06:36:12.360 [TASK1] details here

As you can see, some detail info contains one or more "\n" and it breaks my line-oriented parsing.

I need to get those continuation lines to be slapped back to its original line, like here:
Code:
06:36:12.230 [TASK1] details here
06:36:12.250 [TASK1] details here
06:36:12.260 [TASK1] details here continuation here
06:36:12.360 [TASK1] details here

I think there is a way to tell awk to use [0-9][0-9]:[0-9][0-9]:[0-9][0-9] as a line separator RS, but not sure how to do it. Any pointers would be appreciated.

I am on Ubuntu 8, my awk is:
Code:
 awk -W version
 mawk 1.3.3 Nov 1996


Last edited by rbatte1; 08-04-2017 at 05:47 AM.. Reason: Added ICODE tags
# 2  
Old 08-03-2017
Code:
awk '$0 ~ d {if (e) print e; if (NR>1 && !e) print ""; printf $0; e=""} $0 !~ d {e=e " " $0} END {print e}' d="^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]" infile

These 2 Users Gave Thanks to rdrtx1 For This Post:
# 3  
Old 08-03-2017
Great, works exactly as expected.
# 4  
Old 08-04-2017
Under the assumption there's not too many (i.e. two or more) colons in the continuation line, try
Code:
awk -F: 'NF>2 && NR>1 {printf RS} END {printf RS} 1' ORS=" " file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Bash Script: Echo continuation across many lines

I am writing a bash script that automatically generates a macro program. I want to have an echo on multiple lines and getting an error /home/chaos/instru-correct.sh: line 309: command line is: command not found I am using echo "# The general synopsis of the $mfl" \ ... (2 Replies)
Discussion started by: kristinu
2 Replies

3. Shell Programming and Scripting

sed - Print Edited Line Along With Original Line

Hi, I have an input file like this line1 line2 line3 hello unix how are you This is what I am expecting my output to be line1 line2 #line3 hello unix how are you line3 hello (3 Replies)
Discussion started by: jacobs.smith
3 Replies

4. Shell Programming and Scripting

How to delete a duplicate line and original with sed.

I am completely new to shell scripting but have been assigned the task of creating several batch files to manipulate data. My final task requires me to find lines that have duplicates present then delete not only the duplicate but the original as well. The script will be used in a windows... (9 Replies)
Discussion started by: chino_1
9 Replies

5. Shell Programming and Scripting

The scripts not able to make the file to size 0, every times it go back to its original size

#!/bin/sh ########################################################################################################## #This script is being used for AOK application for cleaning up the .out files and zip it under logs directory. # IBM # Created #For pdocap201/pdoca202 .out files for AOK #1.... (0 Replies)
Discussion started by: mridul10_crj
0 Replies

6. AIX

EEEK - OSLEVEL -r is now reverted back to original level

Dont know what happened, my AIX 53 TL6 os just reverted back to original TL4 from whence I started this week. Is there a commad to check the ODM or kernel or something to ensure stability? (2 Replies)
Discussion started by: mrmurdock
2 Replies

7. Shell Programming and Scripting

Identify matching data in a file and output to original line, in perl

Hi, I haven't done this for awhile, and further, I've never done it in perl so I appreciate any help you can give me. I have a file of lines, each with 5 data points that look like this: AB,N,ALLIANCEBERNSTEIN HLDNG L.P,AB,N ALD,N,ALLIED CAPITAL CORPORATION,ALD,N AFC,N,ALLIED CAPITAL... (4 Replies)
Discussion started by: Pcushing
4 Replies

8. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies

9. Shell Programming and Scripting

Perl script to scan back lines

Hi Perl gurus, I have this file to scan through. Sample lines below: 2008031A, USERNAME, 12345, give ABC, take XYZ, transaction submitted 2008031B, USERNAME, 12346, waiting for processing 2008031C, USERNAME, 12347, Retrieving response 2008031D, USERNAME, 12348, This is not a valid dealing... (3 Replies)
Discussion started by: gholdbhurg
3 Replies

10. UNIX for Dummies Questions & Answers

Mac OS X Script Continuation Character?

Some of my scripts have very long commands that go beyond the horizontal scroll limits of my screen (1024 x 768), even with a very small font. Is there a continuation character (like the option+l "ell") in AppleScript that will let me break up the line? Right now I just press a hard return to... (2 Replies)
Discussion started by: cassj
2 Replies
Login or Register to Ask a Question