Replacing CR (\r) character with sed
Denis Vlasenko
vda.linux at googlemail.com
Sat Feb 24 12:57:55 UTC 2007
On Saturday 24 February 2007 12:33, Alexander Kriegisch wrote:
> I wonder how I can make sed work as a replacement for dos2unix. I do
> know how to strip CR characters with tr or dos2unix, but I have reasons
> to do it with sed besides just wanting to know how. Those reasons include
> - a bug in some tr versions making it strip special characters like
> German umlauts unintentionally (I have no influence on the version
> of tr used by other people) and
> - dos2unix not being part of our DSL router firmware mod's busybox
> (again, I have it, but many others don't).
>
> I played around with several variants working in other sed versions,
> tried to use basic regex mode as well as the -r switch for extended
> regex syntax, but to no avail. BTW, I have not tried to put the sed
> script into a file, as I want to use it as a command line argument.
bash-3.2# echo -ne 'dos\r\ntext\r\n' | hexdump -C
00000000 64 6f 73 0d 0a 74 65 78 74 0d 0a |dos..text..|
0000000b
bash-3.2# echo -ne 'dos\r\ntext\r\n' | sed $'s/\r//g' | hexdump -C
00000000 64 6f 73 0a 74 65 78 74 0a |dos.text.|
00000009
--
vda
More information about the busybox
mailing list