How to count lines in a document?

后端 未结 24 1415
慢半拍i
慢半拍i 2020-11-27 08:47

I have lines like these, and I want to know how many lines I actually have...

09:16:39 AM  all    2.00    0.00    4.00    0.00    0.00    0.00    0.00    0.0         


        
相关标签:
24条回答
  • 2020-11-27 09:33
    wc -l <file.txt>
    

    Or

    command | wc -l
    
    0 讨论(0)
  • 2020-11-27 09:33

    Use nl like this:

    nl filename
    

    From man nl:

    Write each FILE to standard output, with line numbers added. With no FILE, or when FILE is -, read standard input.

    0 讨论(0)
  • 2020-11-27 09:33

    I just made a program to do this ( with node )

    npm install gimme-lines
    gimme-lines verbose --exclude=node_modules,public,vendor --exclude_extensions=html
    

    https://github.com/danschumann/gimme-lines/tree/master

    0 讨论(0)
  • 2020-11-27 09:36

    Or count all lines in subdirectories with a file name pattern (e.g. logfiles with timestamps in the file name):

    wc -l ./**/*_SuccessLog.csv
    
    0 讨论(0)
  • 2020-11-27 09:36

    This drop-in portable shell function [ℹ]  works like a charm. Just add the following snippet to your .bashrc file (or the equivalent for your shell environment).

    # ---------------------------------------------
    #  Count lines in a file
    #
    #  @1 = path to file
    #
    #  EXAMPLE USAGE: `count_file_lines $HISTFILE`
    # ---------------------------------------------
    count_file_lines() {
        local subj=$(wc -l $1)
        subj="${subj//$1/}"
        echo ${subj//[[:space:]]}
    }
    

    This should be fully compatible with all POSIX-compliant shells in addition to bash and zsh.

    0 讨论(0)
  • 2020-11-27 09:36

    wc -l file_name

    for eg: wc -l file.txt

    it will give you the total number of lines in that file

    for getting last line use tail -1 file_name

    0 讨论(0)
提交回复
热议问题