1

I have been struggling to do this. I need to replace a line in a document with either blank space or the word "DELETED." The lines are different, and I am running a counter to determine the correct line to replace. So far, I have been using:

sed -ie ''$NUMLINE's/^$/DELETED/' Brown_Adam_CIVForms.txt 

I would like to replace the NUMLINE-th line from this document (whatever it may be) and replace it with either blank space or the word "DELETED." Please help!!

Thank you!!!

Dave
  • 33
  • 1
  • 1
  • 3

2 Answers2

4

Just insert .* between ^ and $. Like:

sed -ie $NUMLINE's/^.*$/DELETED/' Brown_Adam_CIVForms.txt 
mouviciel
  • 66,855
  • 13
  • 106
  • 140
  • This was awesome. Worked perfectly. Thanks! Any advice for only changing the line if the previous line is not "--"? THANKS!!! – Dave Apr 11 '11 at 07:34
  • 1
    Whenever I need to work on more than one line, I switch from `sed` to `awk` or `perl`. – mouviciel Apr 11 '11 at 07:37
0

you can also use awk

awk -vnum=$NUMLINE 'NR==num{$0="DELETED"}1' file
kurumi
  • 25,121
  • 5
  • 44
  • 52