pattern matching lines using the date, and then joining the lines

Hi Guys,

Was trying to attempt the below using awk and sed, have no luck so far, so any help would be appreciated.

Current Text File: The first line has got an "\n", and the second line has got spaces/tabs then the word and "\n"

   TIME           SERVER/CLIENT                      TEXT
02/03/2010 23:44:13 hostname02 hostname01  NBU status: 96, EMM status: No media is
                                          available

 01/03/2010 03:48:14 unknown hostname01  backup of  hostname01 exited with
                                          status 96 (unable to allocate new media for backup,
                                         storage unit has none available)

 22/02/2010 19:44:09 hostname02 hostname01  NBU status: 96, EMM status: No media is
                                          available

 

OUTPUT FILE:

TIME            SERVER/CLIENT                      TEXT
02/03/2010 23:44:13 hostname02 hostname01  NBU status: 96, EMM status: No media is available
01/03/2010 03:48:14 unknown hostname01  backup of client hostname01 exited with status 96 (unable to allocate new media for backup, storage unit has none available)
22/02/2010 19:44:09 hostname02 hostname01  NBU status: 96, EMM status: No media is available
sed -i '$!N;s/\n[ |       ]*//g' file

Try the above code. Now the file will contain the text in the required format

You use the following command to achieve your requirement.

sed -ri '/^\n$/d;s/[ ]{2,}/ /g;s/[\t]{1,}/ /g;' <inputfilename>

-i is used to affect the changes to an original file.

If you don't want,then remove it and the output will be printed on stdout.

Thanks guys, but that didnt work, I am using the aix sed version, and the -i and -r options are not available, I tried both above commands with out the -i and -r options. no luck.

If -i and -r options aren't working.Then,you simply escape the curly braces in my command as follows.This will work.

sed '/^$/d;/^[ \t]\{1,\}$/d;s/^[ \t]\{1,\}\(.*\)/\1/g;s/[ ]\{2,\}/ /g;s/[\t]\{1,\}/ /g;' <inputfilename>

If -r option works,there is no need to escape the curly braces.

With awk...

awk '{gsub("^ *"," ",$0);printf ((/^ [0-9]/?"\n"$0:$0))}' infile

Thks guys for the response, really appreciate it. The sed command didnt work, but the awk did the trick. Thnks once again.