Sign in to follow this  
Followers 0
Justin

Removing @LF's from a txt file

11 posts in this topic

I am working on a script and would like to add a feature that parses through a text file that has a CR & LF at the end of each line, and remove the LF's to leave just a carriage return there. Is there an easy way of doing this?

Share this post


Link to post
Share on other sites



I am working on a script and would like to add a feature that parses through a text file that has a CR & LF at the end of each line, and remove the LF's to leave just a carriage return there. Is there an easy way of doing this?

Hi,

did you try StringReplace?

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

maybe...

$text = "this" & @CRLF & @LF & "that"

MsgBox(64,"test1", $text, 5)

$text2 = StringReplace( $text, @CRLF, @CR)
$text2 = StringReplace( $text, @LF, @CR)

InputBox("","", $text2)

8)

Why not StringReplace($text,@LF,"") ??

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Why not StringReplace($text,@LF,"") ??

Cheers

Kurt

would that replace @CRLF... its not @LF ???

fixed

StringReplace( $text2,

8)

Edited by Valuater

NEWHeader1.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

FileWrite("test-out.txt", StringReplace(FileRead("test-in.txt"), @LF, ""))oÝ÷ Ù«­¢+Ù¥±]É¥Ñ ÅÕ½ÐíÑÍе½ÕйÑáÐÅÕ½Ðì°MÑÉ¥¹IÁ±¡¥±I ÅÕ½ÐíÑÍе¥¸¹ÑáÐÅÕ½Ð줰
I1°1¤¤
either way works just fine

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Alright, I need a way to parse each line in the document. Assuming the document was called CRLF.txt and is in the same directory as the script, it needs to parse the entire 500 lines of the txt file, and either just take out each of the @lf's, or rewrite the document without them while maintaining the same formatting.

The following is what I have as sort of a test script, but all this does is return me a blank new txt file.

$file = FileOpen("CRLF.txt",0)
$string = FileRead($file)
FileClose($file)

$newString = StringReplace($string,@CRLF,@CR)
$file = FileOpen("crlf.txt",2)
FileWrite($file,$newString)
FileClose($file)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The only one line of AutoIt code can do it for you :D

FileWrite('output_file.txt', StringReplace(FileRead('input_file.txt'), @CRLF, @CR))

Of course this is not well readable and without error checking just for demostrate power of AutoIt :P

EDIT: herewasplato & Justin beat me

Edited by Zedna

Share this post


Link to post
Share on other sites

would that replace @CRLF... its not @LF ???

fixed

StringReplace( $text2,

8)

no, but that's not what he is asking for: "and remove the LF's to leave just a carriage return"

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

See what a good post title will bring... lots of help and code.

Must be a slow day on the forum......


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thanks, worked perfectly!

Edited by Justin

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