How do I count the number of rows and columns in a file using bash?

后端 未结 13 730
情深已故
情深已故 2020-12-23 03:09

Say I have a large file with many rows and many columns. I\'d like to find out how many rows and columns I have using bash.

13条回答
  •  一个人的身影
    2020-12-23 04:07

    For rows you can simply use wc -l file

    -l stands for total line

    for columns uou can simply use head -1 file | tr ";" "\n" | wc -l

    Explanation
    head -1 file
    Grabbing the first line of your file, which should be the headers, and sending to it to the next cmd through the pipe
    | tr ";" "\n"

    tr stands for translate.
    It will translate all ; characters into a newline character.
    In this example ; is your delimiter.

    Then it sends data to next command.

    wc -l
    Counts the total number of lines.

提交回复
热议问题