Short and sweet awk solution


  • 0
    W

    #In awk, the predefined variable NR stores the current line number.
    #This allows for an easy throwaway 1 liner solution.
    cat file.txt | awk '{if (NR==10) print $0}'


  • 1
    D

    Useless use of cat, just give the file to to awk like this.

    awk 'NR==10 {print}' file.txt


  • 0
    J

    not good enough for a very large file, try this :

    awk 'NR==10 {print; exit}' file.txt
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.