Remove 1st two rows and last 2 rows

Hi All,
I need to remove 1st 2 line from head and last 2 line from last.
I thought it would be possible by using the Head and tail command.
But after i am using it is not possible by it.
Example:Input file

1
2
3
4
5

Example: Output file

3

But my head and tail command are not working?

head -n 2 filename|tail -n 2

Hi

(not tested)

#x=`cat file | wc -l`
#awk 'NR>2 && NR+1<'$x'' file

Guru.

If your head and tail support it (Linux version should work):

tail -n+3 file | head -n-2
cnt=`cat filec | wc -l`
tail -`expr $cnt - 2` filec | head -`expr $cnt - 4`

Hi guys thanks for help.
But i want to do this in one line only.
As i can execute only one command.

tail -n+3 file | head -n-2 

Is not working.

# head -n 3 file | tail -n1
3

Hi Sorry for wrong input
Input file

1
2
3
:
:
50

Output file

3
:
:
48

Any time i should always remove 1st two row from top and bottom.

sed -e '1,2d' -e '$d' infile | sed '$d'
# cat infile
1
2
3
:
:
50
# sed -n '3,$p;' infile | sed '$d' ; expr `sed -n '$p' infile` - 2
3
:
:
48
sed 'N;2d;$d' infile

or

sed -e N -e 2d -e '$d' infile

tail +3 infile

It would be of great help if you have a chance to explain the above sed command. Thank you.

Hi,

N appends the next line into the pattern buffer and increases the line counter.
If the line counter equals 2 then delete the pattern buffer and this means that the two lines that are in there are deleted.

But never mind, my solution won't work for files with an odd number of lines :o

---------- Post updated at 14:28 ---------- Previous update was at 13:39 ----------

This works better:

 sed -n '1,2d;N;$!P;D' infile