How to convert easily every TAB character to a Space.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

How to convert easily every TAB character to a Space.

#1 Post by alan_b » 02 Jul 2013 06:23

I am using a utility that produces an output report upon a vast number of files.
Every file is reported with its complete path and name on a separate line, e.g.

Code: Select all

W:\#1\   bookmarks-2012-03-10.json

The TAB character between the path and the name is causing me grief,
and I wish to remove each TAB, or replace with a normal Space.
Is there a simple command available in DOS to do this,
or do I have to dust of my tenuous grasp of writing a script and read each each line and replace with something like
http://www.dostips.com/?t=Snippets.Replace

Regards
Alan

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to convert easily every TAB character to a Space.

#2 Post by foxidrive » 02 Jul 2013 07:01

The MORE command has a switch to convert TABs to a number of spaces.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: How to convert easily every TAB character to a Space.

#3 Post by Squashman » 02 Jul 2013 07:05

Those are tabs in the code.

Code: Select all

@echo off
SET VAR1=W:\#1\   bookmarks-2012-03-10.json
echo %VAR1%
SET VAR1=%VAR1:   =%
echo %VAR1%
pause


output

Code: Select all

W:\#1\  bookmarks-2012-03-10.json
W:\#1\bookmarks-2012-03-10.json
Press any key to continue . . .


You could also do this with a FOR LOOP if it is just one tab.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: How to convert easily every TAB character to a Space.

#4 Post by dbenham » 02 Jul 2013 07:53

I think foxidrive is on track for the most convenient answer, although MORE always converts tab into 1 or more spaces. The switch only controls the tab stops. Set the tab stop to 1 to convert every tab into exactly 1 space.

Code: Select all

more /t1 yourfile.log >yourfile.log.new
move /y yourfile.log.new yourfile.log >nul

Or better yet, pipe your command output directly to MORE

Code: Select all

yourCommand | more /t1 >yourfile.log


Dave Benham

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How to convert easily every TAB character to a Space.

#5 Post by foxidrive » 02 Jul 2013 07:56

/t0 removes the tabs

Code: Select all

  /Tn     Expand tabs to n spaces (default 8)

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: How to convert easily every TAB character to a Space.

#6 Post by dbenham » 02 Jul 2013 08:07

foxidrive wrote:/t0 removes the tabs

Code: Select all

  /Tn     Expand tabs to n spaces (default 8)


:shock: :D 8) Thanks, I did not know that :!:

So my statement should be amended to "MORE always converts a tab into 0 or more spaces". It is a shame that there is no option to preserve tabs :(


Dave Benham

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: How to convert easily every TAB character to a Space.

#7 Post by alan_b » 02 Jul 2013 11:06

Many thanks,
MORE is a perfect solution for me

Regards
Alan

Post Reply