Rick's Tech Talk

All Tech Talk, Most of the Time

unix

Printing Line N

If you're in front of UNIX system, you should have access to sed, the UNIX "stream editor", which has a lot of utility to it. Here's a little idiom that comes in handy every now and then.

% sed -n '16p' file.txt
Not bad for 1/2 hour worth of work!

The string '16p' says "print line 16". So to print any particular line out of a file, use sed -n 'Np' file.txt, where N is the line that you want. And if you want a range of lines, use 'M,Np', where M and N are the starting and ending line numbers in question.

Tags: 

Hello Tar J

Yes, I'm familiar with tar. But guess what? Over the past few days while putting together this site, I encountered tar's j switch for the very first time (e.g. tar jxf site.tar.bz2). This enables bzip compression and decompression on my tar archives. Amazing! I still remember being amazed a few years back when someone showed me that you can compress or decompress (via gzip) on the fly in tar by passing in the z switch. Nifty!

Tags: 
Subscribe to RSS - unix