Strict Standards: Declaration of Walker_Comment::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/public/wp-includes/comment-template.php on line 1266

Strict Standards: Declaration of Walker_Comment::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/public/wp-includes/comment-template.php on line 1266

Strict Standards: Declaration of Walker_Comment::start_el() should be compatible with Walker::start_el(&$output) in /home/public/wp-includes/comment-template.php on line 1266

Strict Standards: Declaration of Walker_Comment::end_el() should be compatible with Walker::end_el(&$output) in /home/public/wp-includes/comment-template.php on line 1266

Strict Standards: Redefining already defined constructor for class WP_Dependencies in /home/public/wp-includes/class.wp-dependencies.php on line 31

Strict Standards: Redefining already defined constructor for class WP_Http in /home/public/wp-includes/http.php on line 61
Henry’s Tech Advice #6 - Deleting Spaces @ Henry the Adequate
My name is Henry the Adequate, and I am a superhero
RSS icon Home icon
  • Henry’s Tech Advice #6 - Deleting Spaces

    Posted on March 27th, 2007 Ben 12 comments

    Frustrated writes: Henry. I have a problem with a text file. There are spaces at the beginning of most of the lines and I need to get rid of them. Can you suggest an easy way to do this?

    Greetings Frustrated. You have certainly come to the right place, for I am Henry the Adequate, superhero, and my computer guru-ness is second only to that guy who empties the bins at the office. No, no. I know what you’re thinking, but the bin thing is just a hobby. Professionally he is a a damn fine butcher, and just last week bought a computer for the kids, so you can believe me when I say he knows a thing or two.

    Anyway, thanks to my enormous superheroic brain, the answer to your dilemma is as follows, assuming the file in question is called “file.txt”:

    If you are using Microsoft Windows

    1. Double click on the file “file.txt” to open it in Notepad. This is one of the best text editors ever to be included free with a Windows operating system.
    2. Click at the beginning of the first line you wish to edit. Click and drag from here to just before the first non-space character, then release the mouse button.
    3. Press the “Delete” key on your keyboard (the thing with lots and lots and lots of buttons on it).
    4. Notice how all of the highlighted spaces magically disappear with a single keystroke! Magnificent isn’t it.
    5. Repeat 2,3,4 until you reach the end of the file.
    6. Click on “File/Save” to save your changes.
    7. Click on the little “x” in the top right of Notepad to exit.

    It really is that easy with Windows, thanks to the power of the graphical interface.

    If you are using Macintosh
    Well, no experienced Mac user would be asking such a question, so I am going to assume you are a bit of a newbie. Firstly I would like you to think about that Star Trek movie where Scotty is trying to use a twentieth century system. “Computer,” he says, then waits for a response. That other Star Trek guy hands him the mouse. Of course, thinks Scotty. He holds the mouse up to his mouth. “Computer.”

    “Just use the keyboard,” suggests some person who is really quite unimportant so I will just move on without discussing him any further.

    You see? Scotty’s problem was that he expected the computer to understand his spoken, plain English commands. Your problem, of course, is exactly the opposite - Macs really are that clever. Just pick up the mouse and explain what it is you would like to have done.

    If you are using a Linux/Unix computer
    sed -i ’s/^[ \t]*//’ file.txt

    Conclusion
    I am a really great computer guru guy. In fact I am so clever I even managed to bluff my way through the Macintosh section without anybody noticing I know nothing whatsoever about Apple computers.

    Need help with computer stuff? Henry can help. I promise a timely and definitive response to any technical question asked in the comments here.

    Glossary
    promise - vaguely suggest that something might happen, if you’re really really lucky.
    timely - If it occurs at all it will be within the context of the space-time continuum.
    definitive - My response may contain some definitions, such as these.

     

    12 responses to “Henry’s Tech Advice #6 - Deleting Spaces”

    1. Dear Henry… I’ve added your blog to YouMob. The traffic won’t show up on your site as they use frames but you should get more readers through the link. Keep hanging on down under. It’s spring here so you will be getting colder down there.

    2. Hadn’t heard of that one. Thanks.

      “Cold”, even by our standards, is still a month or more away.

    3. Umm, is this the ’slightly more popular’ one?

      …and who is ‘HENRY’… your alter ego?

      FUN!

    4. Yes, that ^ would be me. :)

    5. Yes, this is indeed the ’slightly more popular’ weblog, which is not saying much, really.

      Henry is this superhero guy.

      And welcome, ice-laden one.

    6. http://bloggerschoiceawards.com/ Nominated Henry here.

    7. Wow, thanks. Wonder if I’ll get a vote.

    8. Or you can open the file in Notepad, select Edit>Replace (or hit Ctrl+R on the keyboard). In the ‘Find What’ box, enter two spaces, leave the ‘Replace With’ box blank. Click once on ‘Replace all”. Now, all of the extra spaces are gone, leaving single spaces between words. Click the ‘X’ in the upper right hand corner and when the computer asks you if you would like to save the file, click on ‘Yes’.

      And WordPad is much more powerful than Notepad.

    9. A worthless prize to anybody who can spot the flaw in John’s suggestion.

    10. I’m not sure what that would be Ben. It works fine for me.

    11. Hi John. Your solution works very well for deleting multiple spaces from anywhere in the document, however it does not solve the problem at hand, which is deleting all space from the beginning of each line.

      Your solution fails because:
      1. It may delete spaces not at the beginning of lines.
      2. It will fail to delete a single space at the beginning of a line.

    12. notebad