Hands-on Lab·LPIC-1
Regular expressions and the text tools
Objective 103.7 examines regular expressions by name, and 103.2 the filters that use them. This guide answers real questions about one log file - who failed, who appears most, which lines are which - and finishes with xargs, which exists because some commands do not read standard input at all.
101: GNU and Unix Commands Guide 9 of 33 Beginner
- OSUbuntu 26.04 LTS
- Kernel7.0.0-30-generic
- systemd259
- TimeAbout 18 min
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| LPIC1-A01 | 192.168.0.76 | Ubuntu 26.04 LTS | Debian-family host - dpkg and apt, which objective 102.4 names | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when a log, a CSV or any other text file has to answer a question - who appears most, which lines failed, what is in the third column. This matters because the answer is usually one pipeline away, and opening a 200,000-line log in an editor is how an afternoon disappears.
- anchoring a pattern to the start or end of a line with
^and$, and inverting a match with-v - counting matches with
grep -cand non-matches withgrep -vcon the same file - building a frequency count with the
sort | uniq -c | sort -rnidiom - choosing between
awkfor a field test andsedfor a substitution, with both run on the same log - feeding filenames into
wcwithxargs, and surviving a filename that contains a space
Before you start
- streams-pipes-and-redirection
-
Anchors, alternation, and counting
-
Fields, sorting and counting occurrences
-
awk when a field decides, sed when text changes
-
xargs, for commands that ignore stdin