-1

How to see first and last 5 lines of file?

Right now I am using

head filename ; tail filename

Any other way around and more efficient?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Raja G
  • 5,749
  • 12
  • 44
  • 67
  • @don_crissti yes yes , I have given that code above for example. I used to do -n 5 while I need it. – Raja G Mar 10 '16 at 14:41

2 Answers2

3

You only need to process file one time:

{ head -n 1; tail -n 5; } <file
cuonglm
  • 150,973
  • 38
  • 327
  • 406
0

I have written some small shell script and it works good for me

virt01@virt01:~/test$ echo "alias myv='/home/virt01/test/myv.sh'" >> ~/.bashrc ; bash
virt01@virt01:~/test$ myv
^C
virt01@virt01:~/test$ myv line.txt
I am 1 line
I am 2 line
I am 3 line
I am 4 line
I am 5 line
============
I am 16 line
I am 17 line
I am 18 line
I am 19 line
I am 20 line
virt01@virt01:~/test$ cat myv.sh
#!/bin/bash

head -n 5 $1
echo "============"
tail -n 5 $1


virt01@virt01:~/test$
Raja G
  • 5,749
  • 12
  • 44
  • 67