Jump to content



Photo

  • Please log in to reply
6 replies to this topic

#1 Shasoosh

Shasoosh

    Neowinian Senior

  • Joined: 29-August 05

Posted 03 October 2012 - 13:58

So i have this txt file https://dl.dropbox.c...7838/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.


#2 Max Norris

Max Norris

    Neowinian Senior

  • Tech Issues Solved: 17
  • Joined: 20-February 11
  • OS: Windows 8.1, BSD Unix
  • Phone: HTC One (Home) Lumia 1020 (Work)

Posted 03 October 2012 - 14:06

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.

#3 Packet1009

Packet1009

    Neowinian

  • Joined: 13-February 04
  • Location: Ontario

Posted 03 October 2012 - 14:09

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

#4 Farstrider

Farstrider

    The Clash

  • Joined: 16-March 03
  • Location: Somerset West, Cape Town, SA
  • OS: Arch Linux

Posted 03 October 2012 - 14:16

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!

#5 OP Shasoosh

Shasoosh

    Neowinian Senior

  • Joined: 29-August 05

Posted 03 October 2012 - 14:20

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! :)

#6 Max Norris

Max Norris

    Neowinian Senior

  • Tech Issues Solved: 17
  • Joined: 20-February 11
  • OS: Windows 8.1, BSD Unix
  • Phone: HTC One (Home) Lumia 1020 (Work)

Posted 03 October 2012 - 14:36

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.

#7 OP Shasoosh

Shasoosh

    Neowinian Senior

  • Joined: 29-August 05

Posted 03 October 2012 - 14:38

Yea, just edited my last post. Thanks again!