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?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Information

This entry was posted on July 5, 2011 by in regular and tagged , , , , .
%d bloggers like this: