Day 4 [part :- 3] :- ๐ Mastering Text Processing in Ubuntu: grep, find, awk, and sed ๐
![Day 4 [part :- 3] :- ๐ Mastering Text Processing in Ubuntu: grep, find, awk, and sed ๐](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1720633694485%2F94575e55-80f5-4041-9253-2389f8f570b3.png&w=3840&q=75)
"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops
The grep, find, awk, and sed commands are powerful tools in the Ubuntu command line interface (CLI) used for searching, processing, and manipulating text. Here's an explanation of each:
grep
grep (Global Regular Expression Print) is used to search for specific patterns within files. It supports regular expressions, making it a versatile tool for pattern matching.
Basic Usage:
grep 'pattern' filename
#for multiple
grep "pattern" filename1 filename2
#for printing with line number
grep -n "pattern" filename
Example:
grep 'hello' file.txt
This command searches for the word "hello" in file.txt.

find
find is used to search for files and directories within a directory hierarchy. It can search by name, type, size, modification time, and more.
Basic Usage:
find [path] [expression]
Example:
find /home/user -name "*.txt"
This command searches for all .txt files in the /home/user directory.

awk
awk is a powerful programming language for pattern scanning and processing. It is used for manipulating data and generating reports.
Basic Usage:
awk 'pattern {action}' filename
Example:
awk '{print $1}' file.txt
#for multiple
awk '{print $1,$2,...}' file.txt
This command prints the first column of each line in file.txt.

sed
sed (Stream Editor) is used for parsing and transforming text. It can perform basic text transformations on an input stream (a file or input from a pipeline).
Basic Usage:
sed 's/pattern/replacement/g' filename
#g means global and you can use also number , like how many time you want to change it
Example:
sed 's/hello/world/' file.txt
This command replaces the first occurrence of "hello" with "world" in each line of file.txt.
These commands are essential for text processing and file management in the Ubuntu CLI, providing robust functionality for a variety of tasks.

Thank you for reading!
ยฉ 2024 Anand Raval. All rights reserved.




