Using variable inside of sed -i (regex?) bash

后端 未结 2 1904
遇见更好的自我
遇见更好的自我 2021-01-26 03:47

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

2条回答
  •  死守一世寂寞
    2021-01-26 04:26

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

提交回复
热议问题