• 0

This is going to be complicated to explain... txt file coding(?)


Question

So i have this txt file https://dl.dropbox.com/u/17838/testme.txt

as you can see it's 3 diffrent ip addresses. In Internet explorer in looks like this:

x.x.x.x:x

x.x.x.x:x

x.x.x.x:x

If you'll download and open it in notepad you'll see something like this:

x.x.x.x:xx.x.x.x:xx.x.x.x:x

Now, i can change the above in notepad to:

x.x.x.x:x

x.x.x.x:x

x.x.x.x:x

and save the file and it would look the same on internet explorer.

If i'll create a new txt file and write in it x.x.x.x:xx.x.x.x:xx.x.x.x:x

it will look like this on Internet explorer: x.x.x.x:xx.x.x.x:xx.x.x.x:x

My question is, how Internet explorer (or notepad++ for that matter) knows the first ip ended and that it needs to go down a raw in the original file.

Once i'll figure that out, i want to code something that will convert this:

x.x.x.x:x

x.x.x.x:x

x.x.x.x:x

into this:

x.x.x.x:xx.x.x.x:xx.x.x.x:x

And still keep the rows in it.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

As a guess, it looks like you just might be stumbling over line endings. *Nix systems typically go with LF (ASCII 10), Windows goes with CR/LF (ASCII 13, 10). (Makes it fun when you're editing text files on a Unix box via a Windows desktop, and vice versa.) If you're using NotePad++, you'll see "Unix" in the status line, it's detecting the line endings and adjusting itself appropriately. Might help if you visualize it, View->Show Symbol->Show End of Line in NotePad++. Should be a simple matter of your code adding or removing the carriage returns in your text file as needed depending on your needs.

Link to comment
Share on other sites

  • 0

CR LF at the end of each line.

notepad++ can insert those.

save your file in notepad++ and then upload to test?

edit: above post says it all

Link to comment
Share on other sites

  • 0

As a guess, it looks like you just might be stumbling over line endings. *Nix systems typically go with LF (ASCII 10), Windows goes with CR/LF (ASCII 13, 10). (Makes it fun when you're editing text files on a Unix box via a Windows desktop, and vice versa.) If you're using NotePad++, you'll see "Unix" in the status line, it's detecting the line endings and adjusting itself appropriately. Might help if you visualize it, View->Show Symbol->Show End of Line in NotePad++. Should be a simple matter of your code adding or removing the carriage returns in your text file as needed depending on your needs.

Pretty much this, nice succinct explanation!

Link to comment
Share on other sites

  • 0

As a guess, it looks like you just might be stumbling over line endings. *Nix systems typically go with LF (ASCII 10), Windows goes with CR/LF (ASCII 13, 10). (Makes it fun when you're editing text files on a Unix box via a Windows desktop, and vice versa.) If you're using NotePad++, you'll see "Unix" in the status line, it's detecting the line endings and adjusting itself appropriately. Might help if you visualize it, View->Show Symbol->Show End of Line in NotePad++. Should be a simple matter of your code adding or removing the carriage returns in your text file as needed depending on your needs.

Interesting stuff and great info. I was never aware of this. Ok, so i see the LF in notepad++ with UNIX just like you said. In the file i want to convert i see

x.x.x.x:xCR LF so my guess is that i need some how to remove all the CR from the file and i'm done?

Any simple way to do it automatically to a txt file? i don't mind even using a simple batch for it.

For some reason the system we are using at work only accepts one long string in a txt file with LF only.

Edit: dos2unix did the trick. Thanks guys! :)

Link to comment
Share on other sites

  • 0

Bunch of different ways you could go about it. Personally not a fan of reinventing wheels, especially for something simple like this. DOS2Unix (or Unix2DOS, depending on which way you're going) is pretty easymode and is available for pretty much everything under the sun. For a Windows version, here's one of many ports. http://sourceforge.n...jects/dos2unix/ Just run it with the text file name as the parameter and done. Of course it's super trivial to write a quick search and replace in whatever language you use if you need something more flexible, but for straight conversion, this is about as easy as it gets.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.