Posts Tagged ‘sed’

Extracting lines with sed

Friday, January 30th, 2009

Say you have a file and want to pull a line out of the middle, for example line 4 from functions.php:

  • sed -n 4p functions.php

function uuid() {

If you want to pull a range, say lines 4 through 10:

  • sed -n 4,10p functions.php

function uuid() {
return sprintf( ‘%04x%04x-%04x-%04x-%04x-%04x%04x%04x’,
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
mt_rand( 0, 0×0fff ) | 0×4000,
mt_rand( 0, 0×3fff ) | 0×8000,
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) );
}