0

Can someone tell me that how we do cut and paste in ed, for example for the following question?

Write a script for ed which moves all lines starting with character # to the end of the input file?

Kusalananda
  • 333,661
Somojel
  • 41
  • 1
    Is this homework? I suggest reading the manpage for ed, trying with what you've learned, and editing your questiin with where you are having trouble if you can't get it to work. – Nasir Riley Apr 13 '18 at 19:16
  • i tried for /etc/passwd as ed /etc/passwd <<\END – Somojel Apr 13 '18 at 19:44

1 Answers1

4

This question is worded like a homework question. You will learn very little by having the answer given to you.

g/^#/m$

This applies the move-to-end command (m$) to all lines matching /^#/. All that is missing is to write the result back to the original file. For an extra challenge, combine this with your last question and come up with a way of commenting out line 10 through to 20 and move them to the end of the file, not touching other commented out lines.

Kusalananda
  • 333,661