- Nikhil Bhaskar
- May 16, 2021
wc Command for (Count Number of Lines, Words, and Characters) In Linux operating systems, the wc command allows you to count the number of lines, words, characters, and bytes of each given file or standard input and print the result.
wc stands for word count. As the name implies, it is mainly used for counting purpose.
- It is used to find out number of lines, word count, byte and characters count.
- By default it displays four-columnar output.
- First column shows number of lines present in a file specified, second column shows number of words present in the file, third column shows number of characters present in file and fourth column itself is the file name which are given as argument.
To specify the output of the number of lines in file.
wc -l name_of_file
To specify the output of the number of characters in a file.
wc -c name_of_file
To specify the output of the number of words containing in a file.
wc -w name_of_file
To specify the -m option ‘wc’ command displays count of characters from a file.
wc -m name_of_file
This command is to show or print the calendar of the current month.
Using this command we can print the calendar of the any year or month.
To print the calendar of the specific month type the following command.
cal name_of_month name_of_year
To print the calendar of the specific year type the following command.
The fgrep filter is used to search for the fixed-character strings in a file. This command is useful when we need to search for strings which contain lots of regular expression meta characters, such as “^”, “$”, etc.
Options with Description:
- -c : It is used to print only a count of the lines which contain the pattern.
- -h : Used to display the matched lines.
- -i : During comparision, it will ignore upper/lower case distinction.
- -l : Used to print the names of files with matching lines once, separated by new-lines. It will not repeat the names of files when the pattern is found more than once.
- -n : It is used precede each line by its line number in the file (first line is 1).
- -s : It will only display the error messages.
- -v : Print all lines except those contain the pattern.
- -x : Print only lines matched entirely.
- -e pattern_list : Search for a string in pattern-list (useful when the string begins with a “-“).
- -f pattern-file : Take the list of patterns from pattern-file.
- pattern : Specify a pattern to be used during the search for input.
- file : A path name of a file to be searched for the patterns. If no file operands are specified, the standard input will be used.
To display the count of number of matches. We can find the number of lines that match the given string.
fgrep -c ‘pattern want to find’ filename
In this blog we have seen the usage of fgrep, cal and wc commands. These are linux basics commands which we use on daily bases and for perform daily operations.