I\'ve looked at the other sed
pages here and i cannot find one that uses -i
with a variable in the regex search portion. I am trying to cut out a reque
It would seem you want to delete a specific line from a file. You're hopefully getting a single line number in your line
variable (but beware - if you have multiple lines that match, you're going to get a list of numbers, and that will cause the rest of your process to explode). The problem you have is that the command you are feeding sed
is simply the line number - you are not specifying anything for sed
to do with that line number. So, perhaps you want this:
sed -i "${line}d" file.txt
If I've misunderstood your question, and you're not wanting to delete that line, but simply print it, then replace the d
with p
...
I assume, you mean remove line
when you say cut out line
.
Try using grep
with -v
option. I believe you don't need sed
here.
grep -v "$3" ./myresolv.conf
Or if you want to delete line in the file itself
sed -i.bak "/$3/d" ./myresolv.conf
It's good to use -i
with .bak
to create backup file before overwirting changes.