Computing.Net > Forums > Windows XP > Batchfile: Removing spaces from txt

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batchfile: Removing spaces from txt

Reply to Message Icon

Name: blink
Date: March 22, 2006 at 05:23:10 Pacific
OS: XP
CPU/Ram: P4 1GB
Product: HP
Comment:

I've made a batch file that lists the users in a security group.

It has three options to list the users, samid, samid and description or just the description.

It exports a list like the following:

Account01 Smith, Bob
Account02 Rob Johnson

I want to run a command that removes the spaces before the samid and after the displayname. I want the spaces in between the samid and displayname to be reduced to just one space. So the above turns into.

Account01 Smith, Bob
Account02 Rob Johnson



Sponsored Link
Ads by Google

Response Number 1
Name: blink
Date: March 22, 2006 at 05:27:35 Pacific
Reply:

I see that the forum reduces the spaces automatically. To clarify I've substituted the spaces for underscores:

Current situation:

__Account01______Smith,_Bob___________
__Account02______Rob_Johnson___________

Desired:

Account01_Smith,_Bob
Account02_Rob_Johnson


0

Response Number 2
Name: IVO
Date: March 22, 2006 at 06:22:02 Pacific
Reply:

Just save the following line as a batch

@For /F "tokens=1-5" %%A in (%1) Do (
Echo %%A %%B %%C %%D %%E >> %2)

Where each variable (%%A, %%B and so on) is separated by a blank.
Then type BatchName FileIn FileOut and you are done.

I assume there are max 5 items per line.


0

Response Number 3
Name: IVO
Date: March 22, 2006 at 06:25:08 Pacific
Reply:

Sorry, better instead of Echo code @Echo.


0

Response Number 4
Name: blink
Date: March 22, 2006 at 06:50:46 Pacific
Reply:

Works wonderful man, thanks!

Is it possible to add a character to the end of each line? Like a ;?


0

Response Number 5
Name: IVO
Date: March 22, 2006 at 06:58:42 Pacific
Reply:

Just add what you want after the last variable or between them, e.g.

Echo %%A %%B %%C %%D %%E;

adds ; at the end of the line, while

Echo [%%A] [%%B] [%%C] [%%D] [%%E]

puts brackets around items; in this case you have to adjust the numbers of items per line, e.g. replacing 1-5 with 1-3 and scaling the variables to %%A %%B %%C.


0

Related Posts

See More



Response Number 6
Name: blink
Date: March 22, 2006 at 07:42:16 Pacific
Reply:

Great stuff, thanks!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batchfile: Removing spaces from txt

removing items from rightclick menu www.computing.net/answers/windows-xp/removing-items-from-rightclick-menu/12408.html

Remove ME from dual boot www.computing.net/answers/windows-xp/remove-me-from-dual-boot/87517.html

remove programms from autostart www.computing.net/answers/windows-xp/remove-programms-from-autostart/13775.html