2

Suppose I have the file temp.txt with the following content:

1
2
3
4
5
6

How would you read the file's content starting from line number 3 using BASH so that the output would be like this:

3
4
5
6
2
  • What do you mean by "using bash"? Do you just want to cat the file or process it in any way?
    – Sven
    Aug 13, 2014 at 15:00
  • Cat would be great. I just need the lines starting from line number 3.
    – JustAGuy
    Aug 13, 2014 at 15:01

2 Answers 2

6
tail -n +3 filename 

shows all lines, starting from 3 of filename.

0
1

A bash-only solution (for the sake of fun):

#!/bin/bash

C=1

DONE=false

until $DONE ;do
  read LINE || DONE=true

  if [ "$C" -ge "$1" ]; then
    printf "%s\n" $LINE
  fi

  C=$(($C+1))
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.