Jump to content

Need help to Insert CRLF[Stringregexp]


Recommended Posts

Hi all,

I would need help to insert @CRLF in between a cluster of data form a log files using regex. The log files are 60MB to 80MB

Data_before

rabbit_1-01

rabbit_1-02

rabbit

parrot_2

parrot_2

After using the script below by randallc

rabbit_1-01

rabbit_1-02

rabbit

parrot_2

I would like the final data to be

rabbit_1-01

rabbit_1-02

------------- @CRLF inserted before new data

rabbit_1

------------- @CRLF inserted before new data

rabbit

------------- @CRLF inserted before new data

parrot_2

The current code I am using from the forum is shown below

Local $esSrcFile2, $esSrcFile = @TempDir & "\all.txt"
$esResultFile = @DesktopDir & "\Sum23.txt"
FileDelete($esResultFile)
$esFileData = FileRead($esSrcFile)
$esFileData1 = StringRegExpReplace($esFileData, "(?m)^(.*+)\r?\n(?=(?:.*+\r?\n)*?\1$)", "")

FileWrite($esResultFile, $esFileData1)
FileDelete(@TempDir & "\all.txt")

I did manage to find that /r/n are equivalent for CRLF but am having problem not knowing where to insert them.

Please help. thanks

Link to comment
Share on other sites

You can't use quantifiers in lookaround parentheses, PCRE limitation...

Dim $sStr = 'rabbit_1-01' & @LF & _
            'rabbit_1-02' & @CRLF & _
            'rabbit_1' & @CRLF & _
            'rabbit' & @LF & _
            'parrot_2' 

Dim $sPattern = '(?m)^((\w+-?)(?:(?:\d+)?\r?\n)(?:\2(?:\d+)?\r?\n)*)'
$sStr = StringRegExpReplace($sStr, $sPattern, '\1' & @CRLF)
$sStr = StringRegExpReplace($sStr, '(?=\n)(?<!\r)', @CR)
ConsoleWrite($sStr & @LF)
Edited by Authenticity
Link to comment
Share on other sites

Authenticity. Thank you but after running my log files and example given here i am still getting the same result as shown below

rabbit_1-01

rabbit_1-02

rabbit

parrot_2

This is the modified script

Local $esSrcFile2, $esSrcFile = @TempDir & "\all.txt"
$esResultFile = @DesktopDir & "\Sum23.txt"
FileDelete($esResultFile)
$esFileData = FileRead($esSrcFile)

Dim $sPattern = '(?m)^((\w+-?)(?:(?:\d+)?\r?\n)(?:\2(?:\d+)?\r?\n)*)'
$esFileData1  = StringRegExpReplace($esFileData, $sPattern, '\1' & @CRLF)
$esFileData1  = StringRegExpReplace($esFileData, '(?=\n)(?<!\r)', @CR)
;ConsoleWrite($sStr & @LF)

FileWrite($esResultFile, $esFileData1)
FileDelete(@TempDir & "\all.txt")

Could someone help.. I am using Autoit 3.2.10 thanks.

Link to comment
Share on other sites

Hehe, a tiny mistake but anyway:

$esFileData1  = StringRegExpReplace($esFileData, $sPattern, '\1' & @CRLF)
$esFileData1  = StringRegExpReplace($esFileData, '(?=\n)(?<!\r)', @CR) ;?oÝ÷ ÙhZ¶+]¡ë"²Úç$¢{azz-b~'²Úⶫz+)Þ}çÂ+a¢ëZqªë¨­ën®{(Ê°¢}ý¶Çj|©àzƭ欶Øh±ç±¥ç-yÖ®¶­sbb33c¶W4fÆTFFÒ7G&æu&VtW&WÆ6Rb33c¶W4fÆTFFÂb33c·5GFW&âÂb33²b3#³b33²fײ5$Äb¢b33c¶W4fÆTFFÒ7G&æu&VtW&WÆ6Rb33c¶W4fÆTFFÂb33²óÒb3#¶âòfÇC²b333²b3#·"b33²Â5"³µoÝ÷ Øfmlº+^u©e¶jǬnë_¢¶­æ¬·Z·*.ßÛÞ²0+wöË.}øéí"Ýýu·¦¢·¦zj+ÊƯzÚ'¢Ù槢Ø^¯­ì¡»}êۺا²×vjü·¶­é{-®)àjëh×6Local $esSrcFile2, $esSrcFile = @TempDir & "\all.txt"
$esResultFile = @DesktopDir & "\Sum23.txt"
FileDelete($esResultFile)
$esFileData = FileRead($esSrcFile)

Dim $sPattern = '(?m)^((\w+-?)(?:(?:\d+)?\r?\n)(?:\2(?:\d+)?\r?\n)*)'
$esFileData  = StringRegExpReplace($esFileData, $sPattern, '\1' & @CRLF)
$esFileData  = StringRegExpReplace($esFileData, '(?=\n)(?<!\r)', @CR)
;ConsoleWrite($sStr & @LF)

FileWrite($esResultFile, $esFileData)
FileDelete(@TempDir & "\all.txt")
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...