myspacee

convert text file from [ANSI UNIX] to [ANSI PC]

6 posts in this topic

hello to all,

I need to open a [ANSI UNIX] text file and save in [ANSI PC] format,

is possible with Autoit without use external tool ?

thank you,

m.

Share this post


Link to post
Share on other sites



What do you mean by UNIX and PC? Are you referring to the line endings?

That's easy. Just read each character and if you find a line feed, add a carriage return.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

hello to all,

I need to open a [ANSI UNIX] text file and save in [ANSI PC] format,

is possible with Autoit without use external tool ?

thank you,

m.

If it's just the line feed difference then you could use a simple StringReplace.

$sStr = FileRead("C:\some\text\file.txt")
$sStr = StringReplace($sStr, @LF, @CRLF)

EDIT:

Actually, better yet

$sStr = StringStripCR(FileRead("C:\some\text\file.txt"))
$sStr = StringReplace($sStr, @LF, @CRLF)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Now you have me thinking. I'm thinking that what I gave you is actually Mac to Windows.

If that doesn't work then try this one.

$sStr = FileRead("C:\some\text\file.txt")
$sStr = StringReplace($sStr, @LF, "")
$sStr = StringReplace($sStr, @CR, @CRLF)

All of these are untested by the way


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

the linefeeds: ( http://en.wikipedia.org/wiki/Newline )

* LF:   Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others
    * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS
    * CR:   Commodore machines, Apple II family, Mac OS up to version 9 and OS-9

So this should convert all:

Enum $NL_MAC, $NL_WIN, $NL_NIX
Func _NewlineConv($text, $type=$NL_WIN)
; Prog@ndy
    Switch $type
        Case $NL_WIN
            If StringInStr($text,@LF) Then
                Return StringReplace(StringStripCR($text),@LF,@CRLF)
            Else
                Return StringReplace($text,@CR,@CRLF)
            EndIf
        Case $NL_MAC
            If StringInStr($text,@LF) Then
                Return StringReplace(StringStripCR($text),@LF,@CR)
            Else
                Return $text
            EndIf
        Case $NL_NIX
            If StringInStr($text,@LF) Then
                Return StringStripCR($text)
            Else
                Return StringReplace($text,@CR,@LF)
            EndIf
        Case Else
            Return SetError(1,0,$text)
    EndSwitch
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

this resolve:

$sStr = FileRead("C:\some\text\file.txt")
$sStr = StringReplace($sStr, @LF, "")
$sStr = StringReplace($sStr, @CR, @CRLF)

thank you all,

m.

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