Extra 'Space' character in FOR-Pipe construction

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Dragokas
Posts: 43
Joined: 30 Jul 2013 09:42
Location: Ukraine, USSR
Contact:

Extra 'Space' character in FOR-Pipe construction

#1 Post by Dragokas » 13 Jun 2014 05:25

Hi !

I write this code to extract from all txt files the lines with 2 or more '.' character.

Code: Select all

@(for %a in (*.txt) do @(type %a& echo.)) | find ".." > new.txt


All files have 1 string (no CrLf).
That's why I use 'echo.'
But new.txt have an extra 'space'-character on the end of each line.

Can someone explain why?

The code:

Code: Select all

@(for %a in (*.txt) do (echo ..)) | find ".."

Result:
(echo .. )

2 spaces after '..'

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

Re: Extra 'Space' character in FOR-Pipe construction

#2 Post by Squashman » 13 Jun 2014 06:13

did you try removing the spaces before and after the PIPE and redirection characters

Dragokas
Posts: 43
Joined: 30 Jul 2013 09:42
Location: Ukraine, USSR
Contact:

Re: Extra 'Space' character in FOR-Pipe construction

#3 Post by Dragokas » 13 Jun 2014 08:06

Yea, the result is same.

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

Re: Extra 'Space' character in FOR-Pipe construction

#4 Post by foxidrive » 13 Jun 2014 08:32

There is a thread here which discusses the pipe and errant spaces.

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

Re: Extra 'Space' character in FOR-Pipe construction

#5 Post by foxidrive » 13 Jun 2014 08:34

Try this:

Code: Select all

for %a in (*.txt) do find ".." < "%a" > new.txt


You might have to show us some of your data if it needs extra processing.

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

Re: Extra 'Space' character in FOR-Pipe construction

#6 Post by Squashman » 13 Jun 2014 08:49

foxidrive wrote:Try this:

Code: Select all

for %a in (*.txt) do find ".." < "%a" > new.txt


You might have to show us some of your data if it needs extra processing.

I was just going to suggest that because I could not understand why he was using the echo and pipe.

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Extra 'Space' character in FOR-Pipe construction

#7 Post by einstein1969 » 13 Jun 2014 08:57

Dragokas wrote:Hi !

I write this code to extract from all txt files the lines with 2 or more '.' character.

Code: Select all

@(for %a in (*.txt) do @(type %a& echo.)) | find ".." > new.txt


All files have 1 string (no CrLf).
That's why I use 'echo.'
But new.txt have an extra 'space'-character on the end of each line.

Can someone explain why?

The code:

Code: Select all

@(for %a in (*.txt) do (echo ..)) | find ".."

Result:
(echo .. )

2 spaces after '..'


The space in output is only one.

This explain why.

You can produce no space using:

Code: Select all

<nul set /p ".=.."


einstein1969

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

Re: Extra 'Space' character in FOR-Pipe construction

#8 Post by Squashman » 13 Jun 2014 09:01

So he is trying to concatenate the output all onto one line in the output file?

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

Re: Extra 'Space' character in FOR-Pipe construction

#9 Post by foxidrive » 13 Jun 2014 09:20

I get the impression that his data is a single line in a bunch of text files.

Post Reply