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!!!

2 Answers 2

4

Just insert .* between ^ and $. Like:

sed -ie $NUMLINE's/^.*$/DELETED/' Brown_Adam_CIVForms.txt 
Sign up to request clarification or add additional context in comments.

2 Comments

This was awesome. Worked perfectly. Thanks! Any advice for only changing the line if the previous line is not "--"? THANKS!!!
Whenever I need to work on more than one line, I switch from sed to awk or perl.
0

you can also use awk

awk -vnum=$NUMLINE 'NR==num{$0="DELETED"}1' file

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.