πAWK
Awk is a scripting language used for manipulating data and generating reports. TShe awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators.
1. awk {print} app.log:- It will prints every line of data from the specified file.
- awk '{print $1}' app.log :- It will print all the first column of the file.
- awk '{print $1,$2}' app.log :- It will print first and second columns of the files.
- awk '{print $1,$2,$4}' app.log:- It will print the First, Second and Fourth columns only.
- awk '/INFO/ {print $1,$2,$3}' app.log:- It will filter "INFO" from 1,2 &3 columns.
- awk '/INFO/ {count++} END {print count}' app.log:- It will help to count the "INFO" from the File.
- awk '$2 < "08:52:50" {print $2}' app.log :- It will print the time of all column where time is less than "08:52:50".
Options Available in awk Command:
π»SED
SED command in UNIX stands for stream editor and it can perform lots of functions on file like searching, find and replace, insertion or deletion. Though most common use of SED command in UNIX is for substitution or for find and replace. By using SED you can edit files even without opening them, which is much quicker way to find and replace something in file, than first opening that file in VI Editor and then changing it.
SED is a powerful text stream editor. Can do insertion, deletion, search and replace(substitution).
SED command in unix supports regular expression which allows it perform complex pattern matching.
sed -n '/INFO/p' app.log:- It will highlight all the "INFO" keywords from the log file.
-
sed 's/INFO/LOG/g' app.log:- It will change all the "INFO" keyword into the "LOG" keyword in the log file.
-
sed -n -e '/INFO/=' app.log:- It will print the line numbere where "INFO" occur.
-
sed '1,15 s/INFO/LOG/g' app.log:- It will change "INFO" keyword form line 1 to 15 into the "LOG" keyword in the log file.
Options Available in sed Command:
πGREP
The 'grep' command stands for "global regular expression print". grep command filters the content of a file which makes our search easy. It filter searches a file for a particular pattern of characters and displays all lines that contain that pattern. The pattern that is searched in the file is referred to as the regular expression.
grep -i info app.log:- It will filter all the "INFO" keyword from the log log file.
-
grep -i -c info app.log:- It will count all the "INFO" keyword form the log file.
-
ps aux | grep ubuntu:- It will show only the "Ubuntu" active processes.
Options Available in grep Command
Mastering AWK, SED and GREP elevates your command-line prowess, making you a text-processing maestro in the Linux kingdom. ππ