DOS line endings

Post your Gambas programming questions here.
Post Reply
User avatar
thatbruce
Posts: 168
Joined: Saturday 4th September 2021 11:29pm

DOS line endings

Post by thatbruce »

Do we have a simple, straightforward way to fix files with the abominable DOS line endings? In other words, to get rid of the "\r" characters.

Amazing after all these years that I have never had to cope with this before...

I know that there are bash ways of doing it, but
"dos2unix" is not ubiquitous.
the "sed" way is witchcraft (IMPO)
cat <file> | tr -d '\r' is the most elegant but looks terrible in File.Load(Shell(cat <file> | tr -d '\r'>temp$ ( ... blah blah blah

To put it simply, if I load the file all the "\r" characters remain and screw up my parsing of the file. I just want to make them "go away with extreme prejudice".

tia
b
Have you ever noticed that software is never advertised using the adjective "spreadable".
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: DOS line endings

Post by vuott »

Ehmmm... :? what if you used the native Gambas function Replace() ?

https://gambaswiki.org/wiki/lang/replace
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: DOS line endings

Post by BruceSteers »

Yep , I'm with Vuott on this


sNoCR = Replace(File.Load(sDosFileName), "\r", "")

If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 168
Joined: Saturday 4th September 2021 11:29pm

Re: DOS line endings

Post by thatbruce »

Probably because I didn't think of it. :oops:
Thanks guys.
b
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply