[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bi



Jason Costomiris writes:
 > On 11 Apr 1997 jghasler@win.bright.net wrote:
 > 
 > > > THE MIGHTY ED HAS SPOKEN!!!
 > > 
 > > Teco.
 > 
 > Bwah.  Real men edit with cat, sed, awk, head and tail.  Better yet, they
 > write directly to the disk with a hex sector editor.
 > 


sed, head AND tail?   Isn't that a bit extravagent?
head -4 f    ==   sed 4q f

Actually, if you have awk I don't think you need sed.


Here's head and tail with awk



Head() {
	awk "(NR > $1) {exit} {print}" $2
}

Tail() {
	n=`wc -l $2 | awk "{print \\$1 - $1}"`
	awk "( NR < $n ) {next} {print}" $2
}

The syntax is a little different,  use Head 4 f  instead of head -4 f


% Head 4 f
line 1
line 2
line 3
line 4
% Tail 4 f
line 6
line 7
line 8
line 9
line 10
% 

If you have tac,  tail is much easier:

% tac f | Head 4 - | tac
line 7
line 8
line 9
line 10
% 


Reply to: