Prev: extract field
Next: replacing / with - in bash
From: James on 6 May 2010 17:18 How to print head and tail (let's say 7 lines)? JL
From: Bit Twister on 6 May 2010 17:30 On Thu, 6 May 2010 14:18:50 -0700 (PDT), James wrote: > How to print head and tail (let's say 7 lines)? head -7 /some/filename ; tail -7 /same/filename
From: Ed Morton on 7 May 2010 07:31 On 5/6/2010 4:30 PM, Bit Twister wrote: > On Thu, 6 May 2010 14:18:50 -0700 (PDT), James wrote: >> How to print head and tail (let's say 7 lines)? > > head -7 /some/filename ; tail -7 /same/filename > For the OP - if the file contains less than 14 lines do you want the middle ones printed twice? Ed.
From: Ed Morton on 7 May 2010 09:02 On 5/7/2010 6:31 AM, Ed Morton wrote: > On 5/6/2010 4:30 PM, Bit Twister wrote: >> On Thu, 6 May 2010 14:18:50 -0700 (PDT), James wrote: >>> How to print head and tail (let's say 7 lines)? >> >> head -7 /some/filename ; tail -7 /same/filename >> > > For the OP - if the file contains less than 14 lines do you want the > middle ones printed twice? > > Ed. If the answer's no, then use: awk '(NR<=7) || (NR>(nr-7))' nr=$(wc -l < file) file Ed.
From: Dave Gibson on 7 May 2010 14:46
Ed Morton <mortonspam(a)gmail.com> wrote: > On 5/7/2010 6:31 AM, Ed Morton wrote: >> On 5/6/2010 4:30 PM, Bit Twister wrote: >>> On Thu, 6 May 2010 14:18:50 -0700 (PDT), James wrote: >>>> How to print head and tail (let's say 7 lines)? >>> >>> head -7 /some/filename ; tail -7 /same/filename >>> >> >> For the OP - if the file contains less than 14 lines do you want the >> middle ones printed twice? > > If the answer's no, then use: > > awk '(NR<=7) || (NR>(nr-7))' nr=$(wc -l < file) file { head -n 7 ; tail -n 7 ; } < file |