Link to home
Create AccountLog in
Avatar of arundelr
arundelr

asked on

DOS script parse a text file and remove LF line feed charactor

Hi People,

I am using Windows 2000 & XP and would like to use a dos batch script to parse a text file and remove any LF line feed characters.

I have seen various ones to remove CR carriage return but I am specifically interested in removing LF.

Many thanks

Rob.
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this. Seems to work for me with line feeds manually entered into a file with EDIT using Control P Control J

@echo off
del destfile 2>NUL
for /f "tokens=*" %%a in (sourcefile.txt) do echo %%a>%destfile%

Steve
Avatar of arundelr
arundelr

ASKER

Hi Steve,

I created a folder in root dir called c:\testing then put my file with CR/LFs in here and renamed it sourcefile.txt

Then I created script.bat whihc contains this...

@echo off
c:
cd c:\testing
del destfile 2>NUL
for /f "tokens=*" %%a in (sourcefile.txt) do echo %%a>%destfile%

rem END

When I run this script it says the syntax of the command is incorrect?


Rob

It looks OK.  What is the OS?  Can you remove the @echo off please and paste the results of exactly what it does?

The > should actually be >> to append to the file, my typo, sorry.

thanks

Steve
Hi Again,

I changed the > to >> and reoved the @ECHO OFF, here si teh result form a console window...

Oh, and its WinXP Pro I am using, once its working I would use on a W2000 box also.
-----------

C:\testing>script

C:\testing>rem @echo off

C:\testing>c:

C:\testing>cd c:\testing

C:\testing>del destfile  2>>NUL
The syntax of the command is incorrect.

C:\testing>for /f "tokens=*" %a in (sourcefile.txt) do echo %a>>

C:\testing>

-----------
Hope this helps, cheers ;)

SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Hi Again,

I tried your new script,, then realised I needed to change the > to >> again so it kept appending lines to destfile.txt, I ran again and this time got a full output into destfile.txt.  Unfortunately the lines were all terminated by CR/LF as the original was, the only difference seems to be that some of the lines originally started with Tab characters which were removed (which is fine btw)

But it still did not remove the LF characters.  
What are you after.  This will remove any additional LF characters and blank lines but CR/LF is the normal line end in Windows / DOS.  Are you after the file with just a CR at the end of each line then, not CR/LF?

Sorry, don't know what happened with the second > character again.  Odd, pasted it straight from my test batch file!

Steve
Hi,
"Are you after the file with just a CR at the end of each line then, not CR/LF?"

Sorry perhaps I should have been clearer, but yes thats exactly what I am after, a file with no LF at the end of each line.  If its possible to remove CR also thats an added bonus but the LF are my biggest enemy that I want to remove.
If you remove CR and LF there will only be one line in the file??  I don't think you can do this from batch file - you can remove blank lines and extra line feeds (which appear as blank lines) but not change the end of line sequence.

A VBScript can no doubt do this but I don't know VBS well enough or have time to write something at present.  Wait around a while and I'm sure sirbounty or others will be along shortly!

Steve
Hi Steve,

Okidoki, thanks for all your help so far anyway ;)
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Oops - remove the 'stop' from the middle as well...

...and thanx for the invite Steve... :^ )
Was surprised you hadn't jumped in anyway :-)
Steve
Been out of town...FINALLY HOME! :^ )
Thought there had been an oppurtunity to answer a few questions ;-)
Hi Guys,

Thanks very much to you both, I did want to do this in DOS and altough its not 100% possible I thought dragon-its work is half way there so will be helpful to me anyway, sirbountrys VB solution did the trick.

Hope you dont mind me splitting off 50 points to draogon-it but it seemed fair. ;)

Thanks again.
Happy to help.
Thanx for the grade!
Fine by me.... knew sirbounty would come up with something for you.

Steve