Top community members
All Wiki Articles Create Wiki Article

Have you ever heard about encyclopedia for code?

What about: Wiki for Code project?

* because I've tried to share code and my solutions on different services and it was removed or I was unwelcomed
   - maybe it wasn't good place, but this one is.

if you think you have solution that can help someone, you are welcome to share this solution - Click here

Bash - how to count lines in a document?

0 contributions
9 points

To count lines, words or characters we can use wc command:

$ cat /etc/passwd | wc
$ wc /etc/passwd 

Examples: 

1. Single file:

$ wc test.txt
  5  6 16 test.txt

 Where:

  • 5 - number of rows
  • 6 - number of words
  • 16 - number of characters

2. Multiple files:

$ wc foo.txt bar.txt
    40     149     947 foo.txt
  2294   16638   97724 bar.txt
  2334   16787   98671 total 


There are few useful modifications too:

  • wc -l path/to/file - prints only total number of lines (note that if the last line does not have \n, the line will be not counted) 
  • wc -c path/to/file - prints only total number of bytes
  • wc -m path/to/file - prints only total number of character 
  • wc -L path/to/file - prints only length of longest line 
  • wc -w path/to/file - prints only number of words 
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more