Stripping Carriage Return / Line Feed from text file
Jean-Pierre A. Radley
appl at jpr.com
Wed Jul 30 14:01:18 PDT 2008
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
More information about the Filepro-list
mailing list