Author Topic: Any tool to easily remove extra whitespaces/tabs at the end of the each line?  (Read 6938 times)

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               

Prefferably windows one that can do this with all files in folder. I have PSPad and it hass this functionality but it can be applied only to one file which would be very time consuming as I want to check every script I modified.


 


I could also use replacer in PSPad but the mass version doesnt allow me to use subexpressions, otherwise the code would be "[\s\t]+$" but I see no way to perform in on whole folder.


 


I even tried to download GNU sed for windows but that crashed on my windows 7...


 


Does anyone know about something for windows that could handle this task?


 


Alternatively I need someone who can do this task for me on linux...



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0


               

I have a windows solution (Notepad++ - Highlight the text you want to trim then on the menu go Edit/Blank Operations/Trim Trailing Space), but it does not work on multiple files at once. How many files are we talking about here? If it really is say greater than 5-10 files and nobody knows of a windows solution it is possible I could write a program to do so in vb2008 pro. Programming-wise it sounds like a trivial problem. Two little things. If I do write a program you will need the .net framework 3.5 installed and I can't get around to it for a few days.


 


TR



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               


I have a windows solution (Notepad++ - Highlight the text you want to trim then on the menu go Edit/Blank Operations/Trim Trailing Space), but it does not work on multiple files at once. How many files are we talking about here? If it really is say greater than 5-10 files and nobody knows of a windows solution it is possible I could write a program to do so in vb2008 pro. Programming-wise it sounds like a trivial problem. Two little things. If I do write a program you will need the .net framework 3.5 installed and I can't get around to it for a few days.


 


TR




well this issue was raised when I copypasted few lines into spellscripts, so basically all spellscript files, that might be 500? If it was anything below 50 I would do it via PSPad already '<img'>



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0


               

It occurs to me that if you've got a small command-line utility that will do it for a single file, it might be possible to do it with a batch file.


 


TR



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               

Nope. PSPad is a windows editor with GUI only command line parameters it accepts are open file variants.



               
               

               
            

Legacy___greye

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0


               

You can try vim[1] editor using ':bufdo %s/\s\+$// | update' command ([2-3] for details). Otherwise I hadn't experienced issues with sed using MSYS[4].


 


[1] http://www.vim.org


[2] http://vim.wikia.com...unwanted_spaces


[3] http://vim.wikia.com...ultiple_buffers


[4] http://www.mingw.org/wiki/msys



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0


               

OK, I've designed an interface (ie no code yet) that looks like this -


 


TrimEmAll.gif


 


Will that suit? Any other NwN files that are just plain text that I could add to the list of choosable file formats? Please let me know.


 


TR



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               

Yes that would be perfect.



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0


               

I like to reinvent the wheel, so I would have just wrote something in C# to do it.


 


string[] lines = File.ReadAllLines("c:\\my\\text\\file.txt");
string[] newContent = new string[lines.length];
int i = 0;
foreach(string strLine in lines)
{
    newContent[i] = strLine.Trim().Replace(Environment.NewLine,"").Replace("\t","");
    i++;
}
File.WriteAllLines("c:\\new\\text\\file.txt",newContent)


Of course this is in practice slower than most tools that have been developed.

Can be sped up by multi-threading it etc

               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0


               


 


I like to reinvent the wheel, so I would have just wrote something in C# to do it.



string[] lines = File.ReadAllLines("c:\\my\\text\\file.txt");
string[] newContent = new string[lines.length];
int i = 0;
foreach(string strLine in lines)
{
    newContent[i] = strLine.Trim().Replace(Environment.NewLine,"").Replace("\t","");
    i++;
}
File.WriteAllLines("c:\\new\\text\\file.txt",newContent)

Of course this is in practice slower than most tools that have been developed.

Can be sped up by multi-threading it etc

 




well give me exe and I ll be happy with that, I dont need it to be super fast, just not manually intensive '<img'>


               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Any tool to easily remove extra whitespaces/tabs at the end of the each line?
« Reply #10 on: January 27, 2016, 06:16:51 pm »


               

@ShadoooW Here is how the finished utility looks.


 


TrimEmAll.gif


 


Because it's written vb2008 it requires the .net framework 3.5 in order to actually run. Fortunately I believe that all versions windows from Vista (I think) onwards come with that already. It comes with a four page pdf manual. While I have tested it as thoroughly as I can, I have not tested it with the sort of number of files that you intend to use it for. In this case please regard it as a beta - i.e. it works for me but thoroughly read the manual before using.


 


I intend to put it up on the vault but as it was built because of your request I am offering you the chance to try it first. Just pm me and I'll reply with the address for you to download it from.


 


@Baaleos While that is a nice snippet, as written it doesn't solve the problem as written at the start of this thread. The brief was for it to process around 500 files and not just one. Because of the need to process that number of files you would probably need extra code to process command-line arguments due to the fact that the best way to use a small program to do such trimming would be to include a call to it in a batch file. Then there is the error handling...


 


TR



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Any tool to easily remove extra whitespaces/tabs at the end of the each line?
« Reply #11 on: January 27, 2016, 06:46:55 pm »


               

Well that looks perfect. Where can I download it?



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Any tool to easily remove extra whitespaces/tabs at the end of the each line?
« Reply #12 on: January 27, 2016, 10:15:36 pm »


               

To quote myself


 


 Just pm me and I'll reply with the address for you to download it from.

 


TR



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Any tool to easily remove extra whitespaces/tabs at the end of the each line?
« Reply #13 on: January 28, 2016, 11:27:41 am »


               

worked great, thanks, you might want to share it though, very usefull



               
               

               
            

Legacy_Tarot Redhand

  • Hero Member
  • *****
  • Posts: 4165
  • Karma: +0/-0
Any tool to easily remove extra whitespaces/tabs at the end of the each line?
« Reply #14 on: January 28, 2016, 06:33:32 pm »


               

Not until I make those internal changes I mentioned. Two questions. Was the manual OK? How many files did you process and how long did it take?


 


BTW I have realised there is a limit to the number of files it can trim at once but I can't give a figure as it depends on the length of the file names including their extensions (including the '.'). But if say the average figure is 20 characters per file we get a limit of about 3275 files.


 


TR