sed delete the nth line

Say you want to delete the nth line in a file

You do:

sed -i ‘4d’

which deletes the 4th line

I wanted to find the version of tar, and use it in a script.

#tar --version
tar (GNU tar) 1.23
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.

The first script I wrote was this:

 #tar --version | sed '2,$d' | awk '{print $4}'

Then, I modified it slightly:

tar --version | sed '2,$d' | awk '{print $NF}'

That was overkill. I could just have done:

#tar --version | head -1 | awk '{print $NF}'


You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.