Stripping Carriage Return / Line Feed from text file
Scott Walker
ScottWalker at RAMSystemsCorp.com
Wed Jul 30 14:07:02 PDT 2008
-----Original Message-----
From:
filepro-list-bounces+scottwalker=ramsystemscorp.com at lists.celestial.com
[mailto:filepro-list-bounces+scottwalker=ramsystemscorp.com at lists.celest
ial.com] On Behalf Of Jean-Pierre A. Radley
Sent: Wednesday, July 30, 2008 5:01 PM
To: FilePro Mailing List
Subject: Re: Stripping Carriage Return / Line Feed from text file
John Esak propounded (on Wed, Jul 30, 2008 at 12:09:40AM -0400):
| I have always used JP's teeny tiny script he wrote for The Guru
| magazine 100 years ago. But, alas it is only for *nix. Here is is.
| You put it in your path (/usr/local/bin) and call it addcr, then link
| it to delcr with:
|
| Ln addcr delcr
|
| Thatw way it workds in either direction based on the program you call.
|
| Addcr unixfile windowsfile
| Delcr windwsfile unixfile
|
| Nifty, compact, protable to any *nix.
|
|
| : Carriage-Return converter - JP. Radley for The Guru
| # addcr : adds CRs
| # delcr : removes CRs
| [ $# -ne 2 ] &&
| echo Usage: $0 infile outfile && exit
| case $0 in
| *addcr) sed s+$+^M+ <$1 >$2;;
| *delcr) sed s-^M--g <$1 >$2;;
| esac
Instead of addcr linked to delcr, I now use a script which does either
task. I call it cr+-. It could easily be changed to take filename
arguments like addcr|delcr, but as it stands, it's used as a filter.
#!/bin/sh
#@(#)cr+- JPRadley v 1.1
#@(#)adds CRs if not present, strips them if present
#@(#)if you just cat this file, you miss its essence, so instead
#@(#)cat -v this file, so as to see two actual ^M that it
contains
sed '
s-^M--g
t
s+$+^M+
t
'
--
JP
Like fine wine.....
Thanks for your post.
Regards,
Scott
_______________________________________________
Filepro-list mailing list
Filepro-list at lists.celestial.com
http://mailman.celestial.com/mailman/listinfo/filepro-list
More information about the Filepro-list
mailing list