Skip to main content

Command Palette

Search for a command to run...

Day 4 [part :- 3] :- ๐Ÿ” Mastering Text Processing in Ubuntu: grep, find, awk, and sed ๐Ÿš€

Published
โ€ข2 min read
Day 4 [part :- 3] :- ๐Ÿ” Mastering Text Processing in Ubuntu: grep, find, awk, and sed ๐Ÿš€
A

"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.

90DaysOfDevops

Part 44 of 49

So In This Series I am following 90 DaysOfDevops challenge , what i will learn in my devops journey i will share with you with my blogs ,You will get blog on tools which used by devops engineer , example :- Linux,ansible,terraform,docker,etc

Up next

Day 4 [part :- 2] :- ๐Ÿ”— Connecting Two EC2 Instances via SSH: A Step-by-Step Guide ๐Ÿš€

โ€ข How to Connect One EC2 Instance to Another EC2 Instance In this guide, we'll walk through the steps to connect one EC2 instance to another using SSH. This is a common task when you need to manage multiple instances or transfer files between them. P...

More from this blog

A

Anand Raval

118 posts

Hello I am Anand Raval , i contributed my work in robotics(arduino uno) , fronted web devloper,competitive programming, now currently focusing on #90DaysOfDevops