Home > front end >  Using a variable in sed to delete a line number by choice of user
Using a variable in sed to delete a line number by choice of user

Time:10-09

 echo 'which line number would you like to delete'
 read lineNum
 sed -i '"$lineNum"d' speciesDetails.txt

can someone advise how I use a variable within sed to delete a line number? This is currently what I have but it doesn't work

CodePudding user response:

Variables aren't expanded inside single quotes. You should just use double quotes. Use curly braces to delimit the variable from the d command.

sed -i "${lineNum}d" speciesDetails.txt
  • Related