Removing of specific line in text file

前端 未结 2 1804
北海茫月
北海茫月 2021-01-20 02:22

I am working on an option which will be able to remove the line specified if the user types in the exact title and author.

However I will not be able to make it work

2条回答
  •  逝去的感伤
    2021-01-20 03:02

    You're trying to pass a bash variable (two, actually) into a sub-program (sed), but surrounding the expression you're passing in single-quotes, which does no parameter expansion. That means that sed is literally seeing $Title:$Author. Try putting the whole sed expression in double-quotes:

    sed -i "/$Title:$Author/d" BookDB.txt
    

    This will allow bash to expand $Title and $Author before they get into sed.

提交回复
热议问题