• 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.

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.

  • 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!

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

  • 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.

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

    • No registered users viewing this page.
  • Posts

    • The memory and nvme can be swapped and upgraded with standard parts. But the GPU cannot, which is the weakest part of the box. It's a dead product at these prices.
    • Sounds like the debloated build you are running is missing some components that the Photos app and Snipping Tool rely on.
    • Apparently, Microsoft doesn't use water in their taps, washrooms or clean their facility. /sarc
    • Wow, throwback.  VERY VERY briefly - but realised that it wasn't the language I needed for the tasks I was taking on.
    • Apple and Tesla trade secrets reportedly exposed following a Tata Electronics cyberattack by Hamid Ganji Image via Depositphotos.com Tata Electronics has confirmed that it detected a cybersecurity incident in some of its systems. The Indian company is a manufacturing partner of both Apple and Tesla, and the incident may have exposed some trade secrets belonging to the two American companies. The World Leaks ransomware group is said to be behind the attack, and it has reportedly posted up to 200,000 files on the dark web, including component designs and specification documents related to Apple and Tesla products. Tata Electronics told Reuters that its response protocols were deployed immediately and that the “incident has had no impact on our operations across businesses, which remain unaffected.” The ransomware group reportedly sent a ransom demand to Tata Electronics, while Apple has launched an investigation into the incident. World Leaks claims it stole more than 200,000 files totaling over 630GB from Tata Electronics. Some database files on the ransomware group’s website are titled "com.apple.factorydata," which could refer to Apple’s iPhone production operations in India. Moreover, some documents reportedly contain material specifications and quality inspection standards for iPhone circuit board components. However, Apple is not the only affected company. A folder found in the World Leaks database is titled "NV36 Chargeport Controller - North America," which may refer to Tesla Model Y components. Additionally, other files in the database reportedly contain drawings related to Tesla’s Project Highland, the internal codename for the EV maker’s updated Model 3 sedan. To support the authenticity of the stolen files, World Leaks has published documents containing footers that read: "This document contains proprietary and confidential information of Apple Inc." and "information contained herein is deemed confidential, proprietary, and a trade secret of Tesla Inc." Cybersecurity researcher Rajshekhar Rajaharia told Reuters that the database also contains emails, event logs spanning several years, and passport copies of employees, including foreign nationals. Both Tesla and Apple have declined to comment on the scale of the incident.
  • Recent Achievements

    • One Month Later
      nates earned a badge
      One Month Later
    • Week One Done
      Almohandis earned a badge
      Week One Done
    • Rookie
      dorf went up a rank
      Rookie
    • First Post
      mike_rumble earned a badge
      First Post
    • Dedicated
      tuben earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      487
    2. 2
      +Edouard
      201
    3. 3
      PsYcHoKiLLa
      96
    4. 4
      Michael Scrip
      91
    5. 5
      neufuse
      71
  • Tell a friend

    Love Neowin? Tell a friend!