removing the first and last lines of a flat file in unix

Hi,

 How do I remove the firsta nd last lines of a flat file in unix korn shell?
LuckyLucksAsked:
Who is Participating?
 
ozoCommented:
mv file file.$$
sed -n -e x -e '3,$p' file.$$ > file
0
 
omarfaridCommented:
len=`wc -l filename`
len=`expr $len - 1`
head -n $len $filename > newfile
len=`expr $len - 1`
tail -n $len newfile > newfile2
0
 
AkiraIrisCommented:
By line number (1d deletes first line, $d deletes last line):

sed -i'' -e '1d' -e '$d' filename
0
 
LuckyLucksAuthor Commented:
Is that " (opening double quoute) after -i? I tried sed -i -e '1d' -e '$d' myfile and I got roor - illegal option -i
0
 
ozoCommented:
That's '' not "
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.