What's the opposite of head? I want all but the first N lines of a file

前端 未结 8 687
时光说笑
时光说笑 2020-12-07 19:55

Given a text file of unknown length, how can I read, for example all but the first 2 lines of the file? I know tail will give me the last N lines, but

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 20:21

    using awk to get all but the last 2 line

    awk 'FNR==NR{n=FNR}FNR<=n-3{print}' file file
    

    awk to get all but the first 2 lines

    awk 'NR>2' file
    

    OR you can use more

    more +2 file
    

    or just bash

    #!/bin/bash
    
    i=0
    while read -r line
    do
      [[ $i > 1 ]] && echo "$line"
      ((i++))
    done <"file"
    

提交回复
热议问题