1

How can I search for control characters in unix ed(1)?

For example

ed somefile.log <<EOF
1,$s/.*\015//
w
q
EOF

doesn't work. Neither does \r. Obviously sed(1), awk(1) and other editors can do this, however ed has the very useful line move (m) command which is all I need within the bash script I am using.

I am able to accomplish what I want within the script by entering the control character directly (escaping it with C-v in vi, C-q in emacs for example), but this means that binary characters must be present in my otherwise printable text script.

ed Transport2SVN-W0177.log <<EOF
g/^M/s/.*^M//p
w
q
EOF

The ^M is actually character 0x0d.

Rumbleweed
  • 370
  • 1
  • 9

1 Answers1

1

ed doesn't provide any support for converting control characters.

The way you have found of inserting control-characters directly into the script (using Ctrl-V at the keyboard) is portable and it works.

It's possible that particular implementations of ed might support this, but it would not be portable.

David Jones
  • 4,766
  • 3
  • 32
  • 45