0

I want to print the last line of a text file in shell the number of lines in my text are stored in a variable named n when I try to use sed command like this sed -n '$np' I get an error.How can I solve this problem ?

majk99
  • 1

1 Answers1

1

You would use double quotes: sed -n "${n}p" your_file.txt, but you don't need sed for this. Just use tail:

tail -n 1 your_file.txt
chepner
  • 497,756
  • 71
  • 530
  • 681