1. Number of rows, words, and characters of the statistics file
1) Number of lines:
Wc-l file
Cat File | Wc-l
2) Number of words
Wc-w file
Cat File | Wc-w
3) Statistics of characters
Wc-c file
Cat File | Wc-c
4) When not with any parameters, all three are printed, the print order is the number of lines, the number of words, the number of characters
WC file
[Email protected]:~/dl$ WC a.txt
6 6 A.txt
[Email protected]:~/dl$ cat A.txt
Apple
Gold
Iron
Orange
Silver
Steel
[Email protected]:~/dl$
5) Print the longest line in the file
Wc-l file
2. Regular expressions
1) "? "Spaces that may appear before and after the word
For example: to match all the words in a given text, you can use the following regular expression:
( ? [a-za-z]+?] [A-za-z] represents one letter or multiple letters (A-Z and A-Z)
2) Example of regular expression description
^ Line start tag ^tux match line starting with Tux
$ line Tail Mark tux$ matches lines ending with Tux
. Matches any one character hack. Matches Hackl and Hacki, but does not match hackl2 and HACKI1, it only matches a single character
[] Match any one of the characters contained in [character] coo[kl] match cook or cool
[^] matches any character except [^ character] 9[^01] matches 92, 93, but does not match 90 and 91
[-] matches any one of the characters in the range specified in [] [1-5] matches any number from the stroke
? Match previous item 0 times colou?r matches color or colour but does not match Colouur
+ matches the previous item one or more times rollno-9+ matches rollno-99, rollno-9, but does not match rollno-
* Match previous items 0 or more times co*l match cl, col, Cooool, etc.
() Create a substring MA (tri) for matching? x to match Max or matrix
{n} matches a previous item n times [0-9]{3} matches any one 3-digit number and can be extended to [0-9][0-9][0-9]
{N,} The item before must match at least n times [0-9]{2,} matches any number of two-bit or more digits
{n,m} Specifies the minimum and maximum number of times before an item must match [0-9]{2,5} matches a 2-digit number to 5-digit number
| Alternating--matching | Any of the Oct (1st | 2nd) on either side matches the Oct 1st or Oct 2nd
The \ Escape character escapes the special characters described above a\.b match a.b, but does not match AJB. The special meaning of the. is omitted by adding the prefix \ before.
Shell Scripting Learning (v)