Link to home
Start Free TrialLog in
Avatar of mattratt
mattratt

asked on

Windows Shell Script (or BAT file) to strip extra CR character

Hi Folks,

I have a file being produced by a program that has:
1 - some undesired characters at the start of the first line
2 - an extra CR character at the end of each line (each line terminates with CR + CR + LF)

I'm looking for either a BAT file or a windows shell script that can:
 - strip the undesired characters from the start of first line
 - strip one of the two CR characters from the end of each line

All lines will start with one or more numeric digits and should terminate with a single CR+LF combination.

It would be preferable if the existing file could be edited instead of reading and writing to a new file, although that's not strictly required.

Any takers?

Sample file attached!

Cheers,
Matt
sample.csv
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mattratt
mattratt

ASKER

Thanks for solutions! I actually like them both :-)

The invalid characters are non-printable and take up three bytes at the start of the file - but given they appear before the first comma I think I can live with them as-is.

I couldn't pick just one solution given you'd both posted almost instantaneously, hence the point split.  For the sake of the exercise I chose leew's solution - not because it's necessarily better than RobSampson's, I just like the elegance of a Write / Replace / ReadAll in the one line.

Thanks!!
Sure, no problem. Thanks.

Rob.