merging multiple lines into single line

Hi,

  1. Each message starts with date
  2. There is blank line between each message
  3. Each message does not contain same number of lines.

Any help in merging multiple lines in each message to a single line is much appreciated.

AIX: Korn Shell

Error log file looks like below.

2012-04-17-14.19.13.003447 ZRC=0x800D002B=-2146631637=SQLM_RC_EVFULL "monitor full of data"
          DIA8052C The Event Monitor "" has reached its file capacity. Delete
          the files in the target directory "" or move them to another
          directory.

2012-04-17-14.19.13.003798 ADM2017C  The Event Monitor "DB2DETAILDEADLOCK" has reached its file capacity. Delete the files in the target directory       "/db/db2cct2/cct2/db2cct2/NODE0000/SQL00001/db2event/db2detaildeadloc
k" or move them to another directory.

2012-04-17-14.19.13.642294

2012-04-17-13.59.56.765915

2012-04-17-11.14.12.503246 ADM5501I  DB2 is performing lock escalation. The affected application
          is named "db.8", and is associated with the workload name
          "SYSDEFAULTUSERWORKLOAD" and application ID
          "10.207.177.21.46719.120417111411"  at member "8". The total number
          of locks currently held is "403", and the target number of locks to
          hold is "201". The current statement being executed is "DELETE FROM
          CC.DOWNLOAD where DNLD IN (select DNLD_ID from
          CC.DOWNLOAD where file_id=3325) AND upd_ts >= current
          timestamp - 1 days".

2012-04-17-11.14.12.504032 ADM5502W  The escalation of "400" locks on table "CC.DOWNLOAD" to lock intent "X" was successful.

Thanks in advance

Hi

perl -00ne 's/\n/ /g;print "$_\n";' file

Guru.

1 Like

Thanks Guru. It works like a charm.
It would be great if you can explain this command.

Hi

The option "00" reads the file in paragraph mode which means every time a blank line is encountered, the content read till then is considered as a record. Now, in the record read, we replace the newline(\n) with a space and hence the lines get joined.

Guru.

Equivalent awk:

awk '{gsub(ORS,FS)}1' RS= infile

But this also removes white space, so perhaps this would be a bit more accurate:

awk '{gsub("\n",FS)}1' ORS="\n\n" RS= infile

or perl:

perl -00lpe 's/\n/ /g;' infile

Thanks Guru for your detailed explanation.

Thanks Scrutinizer for sharing the code using awk. It works as well.