DOS remove linefeed and carriage return ?

October 15, 2010 at 11:47:50
Specs: Windows XP, 2.99Ghz 3.46GB
I have a pipe separated text file with 2 lines. I need to remove the CR/LF from the last line in the file. I must do this using the DOS batch script that created the file.

Text file:
Line1has|WWW|This is a note CR/LF <--- this are not visible
U|12345 CR/LF <-- not visible -- need to remove this one

Line1has|WWW|This is a note CR/LF <---need to keep this
U|12345


See More: DOS remove linefeed and carriage return ?

Report •

#1
October 15, 2010 at 17:48:48
Use DEBUG and shorten it by 2.

===========================================
@echo off > d.d

>> d.d echo n myfile
>> d.d echo l
>> d.d echo rcx
>> d.d echo 40
>> d.d echo w
>> d.d echo q

debug < d.d


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
October 15, 2010 at 20:45:19
@OP, try not to use esoteric tools like debug to do the job. Its hard to maintain and require the knowledge of assembly. Tools already are developed to do this kind of job. If you can, download coreutils for windows and then do this

C:\test> head -n -1 file > temp
C:\test> tail -1 file1 | tr -d "\r\n"  >> temp
C:\test> ren temp file

GNU win32 packages | Gawk


Report •

#3
October 15, 2010 at 20:56:38
"try not to use esoteric tools like debug"

LOL

debug included at least back to DOS 3.10

[In Japanese DOS 3.10 is was SYMDEB. But that's another story.]


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
October 15, 2010 at 21:47:17
>>debug included at least back to DOS 3.10

If not a matter of whether its included back from DOS 3.10...Its a matter of whether its practical to use it or not, without losing sleep over maintaining or debugging it. Furthermore, if there are future changes, its not that easy to change without looking up how to use it.

GNU win32 packages | Gawk


Report •

#5
October 16, 2010 at 02:15:19
LOL win32 utils are not going to run in DOS. [surprise]


=====================================
Life is too important to be taken seriously.

M2


Report •

#6
October 16, 2010 at 05:11:54
After reading a bunch of posts in this forum I'm very happy both of you replied - you are the cream of the crop - Thank you M2 and GhostDog for the quick response.

I tried to run the little script M2 created above, at home so I'd be ready for work on Monday but at home I'm running windows 7 and I have a problem running debug:
'debug' is not recognized as an internal or external command, operable program or batch file.

I would like to continue solving this with a batch solution but i will push to see if I can do this in VB. I'm not in a position to download new tools for production use.

Keep smiling,
InsectWarrior


Report •

#7
October 16, 2010 at 05:28:22
I guess I shouldn't be surprised M$ took debug out. Not a new idea. It's called systematic impoverishment. [Future Shock - Alvin Toffler ca 1969]

You can try putting DEBUG.EXE in your PATH.

http://golden-triangle.com/debug.exe


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
October 16, 2010 at 05:44:11
I'll give it try.
Coming from a Unix environment I didn't think it would be hard. I didn't know how limited or difficult DOS batch is. As I continue working this solution I think I will also pursue a VB solution.

Report •

#9
October 16, 2010 at 09:17:23
>>LOL win32 utils are not going to run in DOS.
Most of the time, the OP would be meaning to say cmd.exe , not pure DOS 6.22

GNU win32 packages | Gawk


Report •

#10
October 16, 2010 at 13:31:57
I think it's less The Man bringing you down, and more DEBUG being 16-bit, and the remnants of the 16-bit environment were removed in x64. MS does offer a free Win32 / x64 debugger, for what it's worth. (Not that it helps here, of course.)

How To Ask Questions The Smart Way


Report •

#11
October 16, 2010 at 17:51:39
InsectWarrior: I think I will also pursue a VB solution.
There are many different versions of VB. It's like calling a Honda Accord a Honda. It might be accurate, but it isn't descriptive and it doesn't look good on the accident report.

VBScript:

Const inFilePath = "something.psv"
Const outFilePath = "out.psv"

With CreateObject("Scripting.FileSystemObject")
  Set inFile = .OpenTextFile(inFilePath)
  Set outFile = .OpenTextFile(outFilePath, 2, True)
End With
outFile.WriteLine inFile.ReadLine
outFile.Write inFile.ReadLine

How To Ask Questions The Smart Way


Report •

#12
October 16, 2010 at 21:56:01
R2 strikes again.


=====================================
Life is too important to be taken seriously.

M2


Report •

#13
October 17, 2010 at 07:23:50
Thank you R2, you are right everything has an assortment of flavors. I wasn't specific because I wasn't sure what I would end up using. Your script works perfectly!
Thank you!!

Report •

#14
October 18, 2010 at 10:15:51
Yeah, I like the idea of just shortening the file by two bytes too, but ya just can't without a complier these days.

How To Ask Questions The Smart Way


Report •

#15
October 18, 2010 at 10:24:14
Hi R2,

Can you show a vbs that will shorten by n chars?


=====================================
Life is too important to be taken seriously.

M2


Report •

#16
October 18, 2010 at 10:34:57
Nope, VBS doesn't have the functionality. VB.NET, VBA, and VB6 all do (because they can load .DLL's, you see), but VBS cannot. That's why I went with copy and modify logic.

How To Ask Questions The Smart Way


Report •

#17
October 18, 2010 at 10:40:27
hmm

Thanks R2


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question