script code for end-line

Polytropon freebsd at
Sat Sep 9 16:33:27 UTC 2017

On Sat, 9 Sep 2017 11:14:02 -0500, edgar wrote:
> I think some example input may be helpful. It sounds like dos2unix
> may be useful. However, sed should be able to help as well.

Yes. In case "search & replace" is a way to go, tools like recode,
iconv, sed or tr are a comfortable way to deal with ^Ms.

>  Either way without knowing exactly what the input may be and exactly
> what you want to accomplish it's hard to say.

It's also important to verify the variable contents at each stage,
compared with the input format, for example, if the lines in question
only contain ^M, that is \r, or \r\n (MS-DOS and "Windows" 2-byte
line break); od -x is a convenient tool to find out.

I have verified the following test to work for the "single byte

	if [ `echo -n ${end_line} | od -x | head -n 1 | awk '{ print $2 }'` = "000d" ]; then
		echo "CR"
		echo "no CR"

It's working in a Rube-Goldberg manner. ;-)

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list