head tail
In class, someone asked me how to extract the second row of a file. I said that a Python script would be the simplest way. How wrong I was! I can't believe I missed it, given the topic of yesterday's lecture, but there is a very simple way to do this using head
, tail
, and a pipe |
.
Suppose data.csv
looks like:
name,score
ian,100000
daniel,1
mike-tyson,10
Then head
works like:
$ head -n 3 data.csv
name,score
ian,100000
daniel,1
In other words, if you give it the option -n3
then it returns the first three lines of the file. tail
works like head
, but gives the last n lines. Now...try using a pipe to tie them together and demonstrate how to extract the second line. Post your answer as a comment on this site.
blog comments powered by Disqus