taT4Nix | Heads or Tails, Read between the lines..

Suppose, there is a file having 14 records and you want to copy only a range of records, like 5-12. So, let us denote 5 as lower bound ($LB) and 12 as upper bound ($UB). Here we go;

cat ${OLD_FILE} | tail -`expr $(cat ${OLD_FILE} | wc -l) - $LB + 1` | head -`expr $UB - $LB + 1` > ${NEW_FILE}

So, the original file is being referred to as ${OLD_FILE} and the newly created one as ${NEW_FILE}. This way, you would get range of lines of text from a file. If you feel there’s something better, you can always comment here.

Advertisements

One thought on “taT4Nix | Heads or Tails, Read between the lines..

  1. Pingback: Solving GCJ 2009 Qualifying Round’s Question « PrayogShala

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