How to detect and fix wrong line breaks?

Help with writing and playing macros

How to detect and fix wrong line breaks?

Postby Moon » Tue Jul 24, 2007 10:24 am

Hello,

I have some problem with Log files where the layout is not good.

In fact, i will have Date / Time at the beginning of each line like this :

2007/07/24 07:05 : Comment / parameter / ...
2007/07/24 07:05 : Comment / parameter / ...
2007/07/24 07:05 : Comment / parameter / ...

But sometimes in my logs i've this :
2007/07/24 07:05 : Comment / parameter / ...
2007/07/24 07:05 :
Comment / parameter / ...
2007/07/24 07:05 : Comment / parameter / ...

What i want to do is to modify the layout to have date / time at each line.
(More easy to read :roll: )

I have think of this solution :
Go to the beginning of each line
If the "first" characters are not 2007/07 (parameter ? :P )
Do Key BACKSPACE
Else goto next line

My problem is : how to search 2007/07 ? :oops:

Thanx for you help and your courage to read me so far :?
User avatar
Moon
Newbie
 
Posts: 1
Joined: Mon Jul 23, 2007 11:00 pm

Re: How to detect and fix wrong line breaks?

Postby Mofi » Tue Jul 24, 2007 11:45 am

Run this macro with macro property Continue if a Find with Replace not found checked:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find RegExp "%#"
Replace All "MaRkEdChAr"
Find RegExp "%^(20[0-9][0-9]/[01][0-9]/[0-3][0-9]^)"
Replace All "#^1"
Find RegExp "^p^([~#]^)"
Replace All "^1"
Find RegExp "%#"
Replace All ""
Find MatchCase "MaRkEdChAr"
Replace All "#"

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

The macro first searches for '#' at start of any line and replaces it with strange string "MaRkEdChAr".

Next the macro marks all lines with '#' at start of the line which starts with 20yy/mm/dd.

Then the macro deletes all DOS line terminations (CR+LF) where the next character is not '#'.

Last the inserted '#' at start of every line with a date is removed and every strange string "MaRkEdChAr" is replaced back to '#'.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4058
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros