Aller au contenu

Photo

Any tool to easily remove extra whitespaces/tabs at the end of the each line?


  • Veuillez vous connecter pour répondre
16 réponses à ce sujet

#1
Shadooow

Shadooow
  • Members
  • 4 465 messages

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



#2
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

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



#3
Shadooow

Shadooow
  • Members
  • 4 465 messages

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



#4
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

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



#5
Shadooow

Shadooow
  • Members
  • 4 465 messages

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



#6
__greye

__greye
  • Members
  • 2 messages

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



#7
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

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



#8
Shadooow

Shadooow
  • Members
  • 4 465 messages

Yes that would be perfect.



#9
Baaleos

Baaleos
  • Members
  • 1 315 messages

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

#10
Shadooow

Shadooow
  • Members
  • 4 465 messages

 

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



#11
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

@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



#12
Shadooow

Shadooow
  • Members
  • 4 465 messages

Well that looks perfect. Where can I download it?



#13
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

To quote myself

 

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

 

TR



#14
Shadooow

Shadooow
  • Members
  • 4 465 messages

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



#15
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

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



#16
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

Dang, the forum notifications are playing up again. I only found out about your more detailed pm via email (and it resurrected a closed pm thread with someone else as well). So I now know how many files you used it on. Sorry about that.

 

TR



#17
Tarot Redhand

Tarot Redhand
  • Members
  • 2 666 messages

Now available to download from the vault via this link to the project page.

 

TR