projectz

Tech, Gadgets, Photography, Social Media and Poor Spelling

Get first and last line from a file

jablan:

I needed to get only first and last line from a file (actually, not a file, but rather output from another command). head -1 and tail -1 can be used to get either first or last, but how to combine the two at the same time? Here’s how. Enter tee:

cat somefile | grep something | tee >(head -1) >(tail -1) > /dev/null

Neat, huh?

Leave a comment

Information

This entry was posted on July 5, 2011 by in regular and tagged , , , , .