Solved Read the first line of the file that ends carriage return

Could some one help in reading a comma delimited file that ends with carriage return <CR>. I have tried with below commandfor /F "tokens=* delims=," %%j in (abc.txt) do ()but it always looking for the <LF> to read the line. Thanks for the help.

Does VBScript can run from command prompt?It can. WScript runs scripts in a windowed environment. CScript runs scripts in a command line environment. Neither will return control until they complete if you call them from a batch file. CScript is preferred because any error messages will be written to StdErr, and not a dialog box that requires user interaction.

It is surprise to me that we don't have an option in batch script to read file content line by line that ends with carriage return.It's not really that surprising if you know the history behind it. It simply wasn't designed (and I use that word loosely) for text parsing. Mostly, it's useful to run a series of predefined commands, or some light file system manipulation. The FOR /F command was added by the WinNT line, I think in the Win2K release.

As a scripting language, it's been succeeded by VBScript, which itself has been succeeded by PowerShell. VBScript doesn't support \r as a line ending, but that's easy enough to work around. PowerShell does allow \r as a line ending, but it does not run scripts by default.

A few months ago, I posted a utility script that would take a text file with Unix / Mac OS line endings and convert it to Windows line endings. It's one of those scripts I wrote for myself, which is why it converts Mac OS' EoL, but doesn't have a prompt after its job is done.

Thanks Razon, I am looking for the batch script solution to do this. I am looking for a way to read only first line with the search of <CR> or any other way, not interested in converting entire file and read first line from the new file.

Tony,I am looking for the line ending with CR (0D), I am interested only first line of the file.Some houw your solution not getting the first line (Win 7).I am not sure why thats happening.

Please see sample file below, please make sure end of the line would be <CR> on all lines

----------------------------------------------------------------------------------------------------------------Ac,Dt,Fm,To,Msg,S ID1,42,13,14,15,168,32,23,24,25,269,22,33,34,35,3610,12,43,44,45,46----------------------------------------------------------------------------------------------------------------I am interested only the first header line and all lines ending with <CR> 0D. Thanks for your help.

I am processing a file that received from external services. That file has <CR> (0D) at the end of each line. It is more than 1GB in size, so don't want to generate new file by replacing the <CR> to some other characters (or <CR><LF>) then read from the generated file.

I just want to read the first line that ends with <CR> from the file using batch script.

depending on the first line I determine what subroutine to be called next.

Not sure how external party generating the file (May be MAC or other O/S). Hope this information is suffice.

Yeah, I'm out of ideas. Some tools are willing to take a \n in lieu of \r\n, but it looks like none of them are willing to take just a \r. I suggest you use a different language. If you're on Win7, your native options are VBScript and PowerShell.

Does VBScript can run from command prompt?It can. WScript runs scripts in a windowed environment. CScript runs scripts in a command line environment. Neither will return control until they complete if you call them from a batch file. CScript is preferred because any error messages will be written to StdErr, and not a dialog box that requires user interaction.

It is surprise to me that we don't have an option in batch script to read file content line by line that ends with carriage return.It's not really that surprising if you know the history behind it. It simply wasn't designed (and I use that word loosely) for text parsing. Mostly, it's useful to run a series of predefined commands, or some light file system manipulation. The FOR /F command was added by the WinNT line, I think in the Win2K release.

As a scripting language, it's been succeeded by VBScript, which itself has been succeeded by PowerShell. VBScript doesn't support \r as a line ending, but that's easy enough to work around. PowerShell does allow \r as a line ending, but it does not run scripts by default.

The information on Computing.Net is the opinions of its users. Such
opinions may not be accurate and they are to be used at your own risk.
Computing.Net cannot verify the validity of the statements made on this
site. Computing.Net and Compnet Ventures, LLC hereby disclaim all responsibility
and liability for the content of Computing.Net and its accuracy.