Add Line to txt batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: Trim space characters problem

#16 Post by foxidrive » 06 Aug 2014 10:34

cumhur_28 wrote:i have txt files like.

Code: Select all

xxxxxxxx_01|54545454548488   
xxxxxxxx_02|89494984694964   



each end of the line has 2 space character
i want to remove this space character.


From your previous posts on this it may be that your batch file has spaces that are causing the issue.
It would be better to fix the batch file than add extra code to manipulate the text again.

Copy and Paste your batch file to a reply in code tags and we can have a look for you.

cumhur_28
Posts: 22
Joined: 22 Jul 2014 13:03

Re: Trim space characters problem

#17 Post by cumhur_28 » 06 Aug 2014 13:01

foxidrive wrote:
cumhur_28 wrote:i have txt files like.

Code: Select all

xxxxxxxx_01|54545454548488   
xxxxxxxx_02|89494984694964   



each end of the line has 2 space character
i want to remove this space character.


From your previous posts on this it may be that your batch file has spaces that are causing the issue.
It would be better to fix the batch file than add extra code to manipulate the text again.

Copy and Paste your batch file to a reply in code tags and we can have a look for you.


hi again
actually some program generate xxxx_01 files. i tried to itimate incompatible files. and this xxx_01 files produced by program and i dont authority to change this so i need to remove by myself

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

Re: Add Line to txt batch

#18 Post by Squashman » 06 Aug 2014 14:23

In order to fix this we need to know which of these scenarios is true.

1) Does the original input file that just has the numbers in it have two spaces at the end of each line?

2) Do you have two spaces at the end of this line of code?

Code: Select all

>>"newfile.txt" echo xxxxxxxx_!i:~-2!^|%%a  

cumhur_28
Posts: 22
Joined: 22 Jul 2014 13:03

Re: Add Line to txt batch

#19 Post by cumhur_28 » 06 Aug 2014 23:46

Squashman wrote:In order to fix this we need to know which of these scenarios is true.

1) Does the original input file that just has the numbers in it have two spaces at the end of each line?

2) Do you have two spaces at the end of this line of code?

Code: Select all

>>"newfile.txt" echo xxxxxxxx_!i:~-2!^|%%a  


1- i cant see original input file i only see output file with two blanks
2-no there is no two spaces on my batch code

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

Re: Add Line to txt batch

#20 Post by Squashman » 07 Aug 2014 07:30

cumhur_28 wrote:1- i cant see original input file i only see output file with two blanks

How is that possible? You would not be able to run the batch file if you were not able to see the input file.

cumhur_28
Posts: 22
Joined: 22 Jul 2014 13:03

Re: Add Line to txt batch

#21 Post by cumhur_28 » 07 Aug 2014 07:36

Squashman wrote:
cumhur_28 wrote:1- i cant see original input file i only see output file with two blanks

How is that possible? You would not be able to run the batch file if you were not able to see the input file.



Thanx for your helps.
actually i guess i misunderstand your question but finaly i did it :)


Code: Select all

@echo off
setlocal enabledelayedexpansion
set source="c:\source.txt"
set dest="c:\source\dest.txt"

(for /f "delims=" %%a in ('more +0 %source% ^| find /v ""') do (
  set line=%%~a
  set line=!line:  =!
  echo !line!
)) > %dest%

MOD EDIT: added code tags.


thanx for your helps

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

Re: Add Line to txt batch

#22 Post by Squashman » 07 Aug 2014 07:54

cumhur_28 wrote:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set source="c:\source.txt"
set dest="c:\source\dest.txt"

(for /f "delims=" %%a in ('more +0 %source% ^| find /v ""') do (
  set line=%%~a
  set line=!line:  =!
  echo !line!
)) > %dest%

That looks nothing like the original code that Aacini gave you. It was a simple fix with the original code if you could have just answered one of the two scenarios correctly.

Post Reply