On 8 Mai, 12:17, Nezhate <mazouz.nezh
...@gmail.com> wrote:
> Hi all,
> I'm looking for command that print any number of lines from a given
> file.
> For example file1.txt contains 100 lines
> using the head command I can printout the first n lines from
> file1.txt.
> using the tail command I can printout the n last lines from file1.txt
> How to do for printing out a block of lines, let say from the 50 th
> line to 68 th line ?
awk 'NR>=50&&NR<=68' yourfile
awk 'NR==50,NR==68' yourfile
> I used this but it fails
In what way does it fail?
> file_name="file1.txt"
> if [ -f $file_name ] ;then
> tail +$1 $3 | head -n$2
Are you sure you intended to use $3 instead of $filename?
> fi
> Another question:
> How to detect the total number of lines from a given file?
wc -l <yourfile
Or if you want to combine that information with the other
command above and use just a single (awk) program
awk 'NR==50,NR==68; END{print NR}' yourfile
Janis
> knowing this it will help me to use a for loop to echo all lines that
> I want to print.
> cheers