Site icon GIXtools

Counting and modifying lines, words and characters in Linux text files

Linux includes some useful commands for counting when it comes to text files. This post examines some of the options for counting lines and words and making changes that might help you see what you want.

Counting lines

Counting lines in a file is very easy with the wc command. Use a command like that shown below, and you’ll get a quick response.

$ wc -l myfile
132 myfile

What the wc command is actually counting is the number of newline characters in a file. So, if you had a single-line file with no newline character at the end, it would tell you the file has 0 lines,

The wc -l command can also count the lines in any text that is piped to it. In the example below, wc -l is counting the number of files and directories in the current directory.

To read this article in full, please click here

Source:: Network World – Linux

Exit mobile version