Replacing CR (\r) character with sed
Alexander Kriegisch
Alexander at Kriegisch.name
Sat Feb 24 13:14:12 UTC 2007
Sorry, Denis,
I want to do this with busybox (ash, not bash). I know it works in a
bash, but when I try this in my busybox, I get the following:
$ uname -a
Linux fritz.box 2.6.13.1-ohio #1 Sun Feb 18 14:18:07 CET 2007 mips unknown
$ echo -ne 'dos\r\ntext\r\n' | hexdump -C
00000000 64 6f 73 0d 0a 74 65 78 74 0d 0a |dos..text..|
0000000b
$ echo -ne 'dos\r\ntext\r\n' | sed $'s/\r//g' | hexdump -C
00000000 64 6f 73 0d 0a 74 65 78 74 0d 0a |dos..text..|
0000000b
--
Alexander Kriegisch
> 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