Convert newlines to something else.

Jean-Pierre Radley jpr at jpradley.jpr.com
Sun Feb 10 14:03:29 AEST 1991


In article <6011 at idunno.Princeton.EDU> tvz at phoenix.Princeton.EDU (Timothy Van Zandt) writes:
>How does one convert newlines to something else in a text file? I cannot
>figure out how to do it with sed, if it is possible at all.

The problem is that you go crazy trying to type the sed commands from the
a shell prompt. You need to go into 'vi' and use the ^V facility to get a true
^M into a script.

This script uses sed to either add or delete CR's, depending on how it's called
(i.e, store it as addcr, linked to delcr).

	:
	# 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

 Jean-Pierre Radley   NYC Public Unix   jpr at jpradley.jpr.com   CIS: 72160,1341



More information about the Comp.unix.questions mailing list