If I have a file name myownfile.txt
which contains 3 lines of text.
foo
hello world
bar
I want to display the line in the middle which is hello world
by using head
and tail
command only.
There have been a few instances in the past, where someone provided a daring solution to some file handling problem with sed
. I never really understood how they worked.
Today I had to do some line editing on huge files with just the basic tools and came across this question. Not satisfied by using combinations of tail
and head
I decided to find out about the true power of sed
.
Reading https://www.grymoire.com/Unix/Sed.html gave me all the information I needed. So I want to share this with anybody else who might stumble upon a similar problem and not know the true power of sed
:
sed -n "2 p" myownfile.txt
The -n
option disables all implicit printing, 2
addresses just the second line and p
prints that specific line to stdout.
should do what you want