Course Content
Linux Essentials for DevOps Automation
The "Linux Essentials for DevOps Automation" training provides a comprehensive understanding of Linux fundamentals tailored to DevOps practices. By mastering these concepts, participants can effectively leverage Linux in DevOps environments to automate tasks, manage infrastructure, and deploy applications with efficiency and reliability.
0/15
Linux Essentials for DevOps Automation

ext handling utilities in Linux are command-line tools designed to manipulate, process, and analyze text data efficiently. These utilities are essential for various tasks such as text processing, searching, sorting, and transforming text files. Here are some commonly used text handling utilities in Linux:

 

1. grep:

Description: Searches for patterns within text files.

Usage: grep pattern file

 

[devnixops@uadev etc]$ cat resolv.conf
# Generated by NetworkManager
search localdomain
nameserver 192.168.22.2

[devnixops@uadev etc]$ cat resolv.conf |grep search
search localdomain
[devnixops@uadev etc]$

 

 

2. sed (Stream Editor):

Description: Processes and transforms text streams using patterns.

Usage: sed 's/pattern/replacement/' file

Example: sed 's/old/new/' file.txt

 

[devnixops@uadev etc]$ sed 's/localdomain/google/' resolv.conf
# Generated by NetworkManager
search google
nameserver 192.168.22.2
[devnixops@uadev etc]$
 
 
3. awk:

Description: Processes and analyzes text data using patterns and actions.

Usage: awk '{print $1}' file

Example: awk '{print $1}' data.txt

 

[devnixops@uadev etc]$ awk '{print $1}' resolv.conf
#
search
nameserver
[devnixops@uadev etc]$
 
 
4. cut:

Description: Extracts specific fields or columns from text files.

Usage: cut -d delimiter -f fields file

Example: cut -d ',' -f 1,3 file.csv

 

[devnixops@uadev tmp]$ cat test
hello,world,devnixops
[devnixops@uadev tmp]$
[devnixops@uadev tmp]$ cat test | cut -d ',' -f 2
world
[devnixops@uadev tmp]$ cat test | cut -d ',' -f 3
devnixops
[devnixops@uadev tmp]$ cat test | cut -d ',' -f 1
hello
 
 
5. sort:

Description: Sorts lines of text files alphabetically or numerically.

Usage: sort file

Example: sort names.txt

 

[devnixops@uadev tmp]$ cat test1 
mango
orange
banana
apple
[devnixops@uadev tmp]$ cat test1 |sort
apple
banana
mango
orange
[devnixops@uadev tmp]$

 

 

6. uniq:

Description: Filters adjacent duplicate lines in sorted text files.

Usage: uniq file

Example: uniq sorted.txt

 

[devnixops@uadev tmp]$ cat test2 
apple
apple
orange
banana
[devnixops@uadev tmp]$ cat test2 | uniq
apple
orange
banana
[devnixops@uadev tmp]$

 

 

7. tr (Translate):

Description: Translates or deletes characters from a text stream.

Usage: tr 'old_chars' 'new_chars' < file

Example: tr '[:lower:]' '[:upper:]' < file.txt

 

[devnixops@uadev tmp]$ cat test3
apple
orange
banana
[devnixops@uadev tmp]$ tr '[:lower:]' '[:upper:]' < test3
APPLE
ORANGE
BANANA
[devnixops@uadev tmp]$

 

 

8. wc (Word Count):

Description: Counts the number of lines, words, and characters in a file.

Usage: wc file

Example: wc -l file.txt

 

[devnixops@uadev tmp]$ cat test2
apple
apple
orange
banana
[devnixops@uadev tmp]$
[devnixops@uadev tmp]$ cat test2 |wc -w
4
[devnixops@uadev tmp]$ cat test2 |wc -l
4

 

 

9. head:

Description: Displays the first few lines of a file.

Usage: head file

Example: head -n 10 file.txt

 

[devnixops@uadev tmp]$ cat test4
This is the first line
2
3
4
5
6
7
8
9
10
11
12
This is the last line of the file
[devnixops@uadev tmp]$ cat test4 | head -n 5
This is the first line
2
3
4
5
[devnixops@uadev tmp]$

 

 

10. tail:

Description: Displays the last few lines of a file.

Usage: tail file

Example: tail -n 5 file.txt

 

[devnixops@uadev tmp]$ cat test4 | tail -n 5
9
10
11
12
This is the last line of the file
[devnixops@uadev tmp]$

 

These text handling utilities provide powerful and efficient ways to manipulate and process text data in Linux. Whether you need to search for patterns, extract specific information, sort lines, or perform other text-related tasks, these utilities offer versatile solutions for text processing needs on the command line. Practice using these utilities to become proficient in handling text data in your Linux environment.