Sign in to follow this  
Followers 0
Sleiman

Padding A Cr/lf Before A String

7 posts in this topic

I have a file txt that has lost all CR/LF characters and now difficult to read. The formatting is gone.

How can I search for specific string and when found, replace it with CR/LF+string.

Example:

Original Format

Name MyName

Address MyAddress

City My City

Current format(bad)

Name MyName Address MyAddress City MyCity

There is more data than the above sample.

Thanks for the help.

Sleiman

Share this post


Link to post
Share on other sites



My advice is to get a text editor that supports regular expressions. See the "Text Editor Wars" in the chat forum. I know that Scite, Crimson, and TextPad support regular expression search and replace.

If you've not used regular expressions before, then, post back or search google.

(I'm not seeing an easy way to directly write an AutoIt script to achieve what you want.)

Hope that helps a bit


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I would suggest anything with regular expressions, but you can do it in autoit if you like.

If it is in the format you say then:

; clipboard version fix
$out=clipget()
$out=StringReplace($out," Name",@crlf & "Name")
$out=StringReplace($out," Address",@crlf & "Address")
$out=StringReplace($out," City",@crlf & "City")
clipput($out)

copy to clipboard, run this, and paste it back in.

Regular expressions are a great thing though.

edit Make sure you back up your data first of course.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

You guys are fast.

Thanks for the tips.

I am familiar with EditPad Pro and have downloaded PowerGrep from JGSoft.

However, I am a bit lost on how to use Regular Expression in these tools. I will try the AutoIt solutions for now.

Thanks Again,

Sleiman

Share this post


Link to post
Share on other sites

OK scriptkitty, you are a genious.

Your solution works beatifully.

Thank You.

Sleiman

Share this post


Link to post
Share on other sites

:whistle: I must be tired. But I'm glad scriptkitty is sharp B)

I was thinking how you could insert cr+lf after MyName, MyAddress, MyCity.

The now-obvious solution is to cr+lf before "Name", "Address", "City".


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

My advice is to get a text editor that supports regular expressions. See the "Text Editor Wars" in the chat forum. I know that Scite, Crimson, and TextPad support regular expression search and replace.

There's also a commandline grep utility for Windows, which talks in regular expressions and does extreme magyk under the control of Au3. :whistle:

<<thinks: Mmmm, maybe I should put details in Scripts And Scraps forum >>

Edited by trids

Share this post


Link to post
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
Sign in to follow this  
Followers 0