When working with multiple files we can carry out hundreds of editing, management or control tasks on them and one of the ones that may be more common is knowing in detail the number of lines that a specific file has..
This can be useful for situations where we must keep an exact control over these files and when using macOS systems we do not always know firsthand how to obtain this information.
For UNIX- based systems , such as Linux , macOS, etc., and Shell- based Windows systems, we have the opportunity to use the wc command to obtain these results with reliability and certainty..
The wc (Word Count) command is a command developed to count lines, words and characters that contain a specific file.
Now we will see how to count lines in macOS High Sierra using this command..
1. How to access and open macOS Terminal
The first step is to access the terminal and for this we have the following options:
- Using "Spotlight", and enter the word terminal there.
- Using the "Go" / "Utilities" / "Terminal" route.
- [/color] + U y en la ventana desplegada seleccionar terminal. Use the key combination Shift + [color = rgb (51,51,51)] ⌘ [/ color] + U and in the displayed window select terminal.
2. How to use macOS WC terminal command
To use this command we must execute the following syntax:
wc -l file
When executing this line, this will be the result obtained:
In this case, the -l parameter indicates that the lines of that file must be counted.
Wc command to count lines, words and characters in a file
Another of the utilities that are practical when using wc, is to omit the -l parameter to get the line count, word count and character count.
For example, we can execute the following:
wc / etc / hosts
This will be the result obtained:
Now, adding the -l parameter will be the result:
wc -l / etc / hosts
In this case we see that only the lines of that file are displayed.
Count lines using wc of any type of data
With wc we can get the detailed information of any file, for example, we can use cat next to wc as follows:
cat / etc / hosts | wc -l
We can see the number of available lines in the hosts file.
If we want to see all the options that wc offers us, we can execute the following command:
man toilet
Thus, we have this useful command to obtain detailed information of each line of a file.