SlideShare a Scribd company logo
Text Processing Tools
grep
• ‘grep’ is used to search for strings and/or regular-expressions
(REGEX) in other commands’ outputs or as a search tool on its
own.
• In order to search for a string within file, we can use:
 # grep -i ’user1' /etc/passwd
user1:x:500:500::/home/user1:/bin/bash
• ‘grep’ will output the entire line in which the string we
searched for was found, as seen in the example above.
grep
• grep has many options we can use; some of the common
ones are:
 -i : case-insensitive; do not mind upper or lower case.
 -v : return anything that is NOT the string we’ve searched for.
 -r / -R : recursive; search through sub-directories as well.
 -q : suppress all normal output; useful when checking and evaluating
in scripts.
• For the full list of options, run: “grep --help” or “man grep”.
grep
• There are two more variants of grep:
 fgrep – suited for string searches only; the searches are performed
faster.
 egrep – suited for extended regex searches.
• grep can also be used as a filter, on the right side of pipes in
order to display only specific outputs:
# ls -l | grep “kf”
-rw-rw-r-- 1 nir test 0 Jul 19 15:11 kfile9
cut
• The “cut” command is used to filter out either fields or
columns of text.
• Syntax:
 cut [options] [filename(s)]
• Options:
 -f’[n]’ : [n] refers to field number(s); the fields must be separated by
a delimiter.
 -d’[delimiter]’ : this option defines which character in our string is
the delimiter; if this option is not supplied by the user, the default
will be used (TAB).
# cut -f'6','7' -d':' /etc/passwd | grep user1
/home/user1:/bin/bash
sort
• The “sort” command enabled sorting of data in numerical or
alphabetical orders.
• Syntax:
 sort [options] [filename(s)]
• Options:
 -m – merge already sorted files
 -r - reverse sort order
 -M – month name sort
 -n – numeric sort
 -u – unique sort; display only the first match of a repetitive string in
the file, only once.
uniq
• The “uniq” command searches for duplicates line of data.
• Syntax:
 uniq [options] [filename(s)]
• Options:
 -u – show only lines that are not repeated
 -d – show only one copy of the duplicate line
 -c – output each line with the count of occurrences
 -I – case-insensitive
tr
• The “tr” command is used to translate characters.
It uses two sets of characters, given as command arguments and converts
them on a char-to-char basis. Is can also:
 Converts letter cases; upper to lower and vice-versa.
 Recognizes special characters, such as n (newline)
 Cannot open files; can only use data from pipes or redirections from
within files.
• Syntax:
 tr [options] charter-list1 charter-list2 < [file]
• Options:
 -d – delete all characters appearing in “chars1”
 -s - replace instances of repeated characters with a single character.
 -cd – delete all characters that are NOT in “chars1”
tail
• The “tail” command prints the end of a file
• Syntax:
 tail [options] [filename(s)]
• Options:
 -n+N print the last N lines (default is 10)
 -n-N print the entire file starting from line N
 -f follow mode. tail will stay active and update on each new line to the
file
head
• The “head” command prints the start of a file
• Syntax:
 head [options] [filename(s)]
• Options:
 -n+N print the first N lines (default is 10)
 -n-N print the entire file until the Nth line

More Related Content

What's hot (20)

PPT
Learning sed and awk
Yogesh Sawant
 
PPTX
Grep - A powerful search utility
Nirajan Pant
 
PPT
Unit5 C
arnold 7490
 
PDF
Unix command line concepts
Artem Nagornyi
 
DOCX
15 practical grep command examples in linux
Teja Bheemanapally
 
PPT
Spsl II unit
Sasidhar Kothuru
 
PDF
Unix / Linux Command Reference
Sumankumar Panchal
 
PPTX
Pipes and filters
vijethabhat85
 
PDF
Unix Command-Line Cheat Sheet BTI2014
Noé Fernández-Pozo
 
DOC
2
satishbb
 
PPT
Regular Expressions grep and egrep
Tri Truong
 
PDF
Unix Basics Commands
Sameeran Jenna
 
PPTX
File management in C++
apoorvaverma33
 
DOCX
Learning Grep
Vikas Kumar CSM®
 
PDF
Unit3 browsing the filesystem
root_fibo
 
PPT
Linux
sravan kumar
 
PPTX
file management in c language
chintan makwana
 
PPTX
Programming in C Session 4
Prerna Sharma
 
PDF
Linux Bash Shell Cheat Sheet for Beginners
Davide Ciambelli
 
Learning sed and awk
Yogesh Sawant
 
Grep - A powerful search utility
Nirajan Pant
 
Unit5 C
arnold 7490
 
Unix command line concepts
Artem Nagornyi
 
15 practical grep command examples in linux
Teja Bheemanapally
 
Spsl II unit
Sasidhar Kothuru
 
Unix / Linux Command Reference
Sumankumar Panchal
 
Pipes and filters
vijethabhat85
 
Unix Command-Line Cheat Sheet BTI2014
Noé Fernández-Pozo
 
Regular Expressions grep and egrep
Tri Truong
 
Unix Basics Commands
Sameeran Jenna
 
File management in C++
apoorvaverma33
 
Learning Grep
Vikas Kumar CSM®
 
Unit3 browsing the filesystem
root_fibo
 
file management in c language
chintan makwana
 
Programming in C Session 4
Prerna Sharma
 
Linux Bash Shell Cheat Sheet for Beginners
Davide Ciambelli
 

Similar to 08 text processing_tools (20)

RTF
Unix lab manual
Chaitanya Kn
 
PPT
L5_regular expression command for linux unix
Devendra Meena
 
DOCX
15 practical grep command examples in linux
Teja Bheemanapally
 
PDF
Command Line Text Processing - RHCSA +.pdf
RHCSA Guru
 
PPTX
Linux commands and examples for students
rijenshvti
 
PPT
grep and egrep linux presentation for lecture
pigog73521
 
PDF
grep.1.pdf
Saravana Kumar
 
PDF
grep.1.pdf
Saravana Kumar
 
DOCX
Unix
lilututu
 
PPTX
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AaravNayan
 
PPT
intro unix/linux 05
duquoi
 
DOCX
Perintah dasar terminal kali linux
Faizalguswanda
 
PDF
Basic linux commands
Akkamahadevi Gowda
 
PDF
Basic commands
ambilivava
 
PPSX
Unix environment [autosaved]
Er Mittinpreet Singh
 
PPTX
Lpt lopsa
ketancmaheshwari
 
PPTX
Linux
RittikaBaksi
 
ODP
Unix tips and tricks
Aleksandar Bilanovic
 
PDF
Unit 8 text processing tools
root_fibo
 
PDF
Unix Tutorial
Sanjay Saluth
 
Unix lab manual
Chaitanya Kn
 
L5_regular expression command for linux unix
Devendra Meena
 
15 practical grep command examples in linux
Teja Bheemanapally
 
Command Line Text Processing - RHCSA +.pdf
RHCSA Guru
 
Linux commands and examples for students
rijenshvti
 
grep and egrep linux presentation for lecture
pigog73521
 
grep.1.pdf
Saravana Kumar
 
grep.1.pdf
Saravana Kumar
 
Unix
lilututu
 
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AaravNayan
 
intro unix/linux 05
duquoi
 
Perintah dasar terminal kali linux
Faizalguswanda
 
Basic linux commands
Akkamahadevi Gowda
 
Basic commands
ambilivava
 
Unix environment [autosaved]
Er Mittinpreet Singh
 
Lpt lopsa
ketancmaheshwari
 
Unix tips and tricks
Aleksandar Bilanovic
 
Unit 8 text processing tools
root_fibo
 
Unix Tutorial
Sanjay Saluth
 
Ad

More from Shay Cohen (19)

PPT
Linux Performance Tunning Memory
Shay Cohen
 
PPT
Linux Performance Tunning Kernel
Shay Cohen
 
PPT
Linux Performance Tunning introduction
Shay Cohen
 
ODP
chroot and SELinux
Shay Cohen
 
ODP
Linux Internals - Kernel/Core
Shay Cohen
 
PPTX
Infra / Cont delivery - 3rd party automation
Shay Cohen
 
PPTX
14 network tools
Shay Cohen
 
PPTX
13 process management
Shay Cohen
 
PPTX
12 linux archiving tools
Shay Cohen
 
PPTX
11 linux filesystem copy
Shay Cohen
 
PPTX
10 finding files
Shay Cohen
 
PPT
07 vi text_editor
Shay Cohen
 
PPT
06 users groups_and_permissions
Shay Cohen
 
PPT
05 standard io_and_pipes
Shay Cohen
 
PPT
04 using and_configuring_bash
Shay Cohen
 
PPT
03 browsing the filesystem
Shay Cohen
 
PPT
02 linux desktop usage
Shay Cohen
 
PPT
09 string processing_with_regex copy
Shay Cohen
 
PPT
01 linux history overview
Shay Cohen
 
Linux Performance Tunning Memory
Shay Cohen
 
Linux Performance Tunning Kernel
Shay Cohen
 
Linux Performance Tunning introduction
Shay Cohen
 
chroot and SELinux
Shay Cohen
 
Linux Internals - Kernel/Core
Shay Cohen
 
Infra / Cont delivery - 3rd party automation
Shay Cohen
 
14 network tools
Shay Cohen
 
13 process management
Shay Cohen
 
12 linux archiving tools
Shay Cohen
 
11 linux filesystem copy
Shay Cohen
 
10 finding files
Shay Cohen
 
07 vi text_editor
Shay Cohen
 
06 users groups_and_permissions
Shay Cohen
 
05 standard io_and_pipes
Shay Cohen
 
04 using and_configuring_bash
Shay Cohen
 
03 browsing the filesystem
Shay Cohen
 
02 linux desktop usage
Shay Cohen
 
09 string processing_with_regex copy
Shay Cohen
 
01 linux history overview
Shay Cohen
 
Ad

Recently uploaded (20)

PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PPTX
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Simplifica la seguridad en la nube y la detección de amenazas con FortiCNAPP
Cristian Garcia G.
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 

08 text processing_tools

  • 2. grep • ‘grep’ is used to search for strings and/or regular-expressions (REGEX) in other commands’ outputs or as a search tool on its own. • In order to search for a string within file, we can use:  # grep -i ’user1' /etc/passwd user1:x:500:500::/home/user1:/bin/bash • ‘grep’ will output the entire line in which the string we searched for was found, as seen in the example above.
  • 3. grep • grep has many options we can use; some of the common ones are:  -i : case-insensitive; do not mind upper or lower case.  -v : return anything that is NOT the string we’ve searched for.  -r / -R : recursive; search through sub-directories as well.  -q : suppress all normal output; useful when checking and evaluating in scripts. • For the full list of options, run: “grep --help” or “man grep”.
  • 4. grep • There are two more variants of grep:  fgrep – suited for string searches only; the searches are performed faster.  egrep – suited for extended regex searches. • grep can also be used as a filter, on the right side of pipes in order to display only specific outputs: # ls -l | grep “kf” -rw-rw-r-- 1 nir test 0 Jul 19 15:11 kfile9
  • 5. cut • The “cut” command is used to filter out either fields or columns of text. • Syntax:  cut [options] [filename(s)] • Options:  -f’[n]’ : [n] refers to field number(s); the fields must be separated by a delimiter.  -d’[delimiter]’ : this option defines which character in our string is the delimiter; if this option is not supplied by the user, the default will be used (TAB). # cut -f'6','7' -d':' /etc/passwd | grep user1 /home/user1:/bin/bash
  • 6. sort • The “sort” command enabled sorting of data in numerical or alphabetical orders. • Syntax:  sort [options] [filename(s)] • Options:  -m – merge already sorted files  -r - reverse sort order  -M – month name sort  -n – numeric sort  -u – unique sort; display only the first match of a repetitive string in the file, only once.
  • 7. uniq • The “uniq” command searches for duplicates line of data. • Syntax:  uniq [options] [filename(s)] • Options:  -u – show only lines that are not repeated  -d – show only one copy of the duplicate line  -c – output each line with the count of occurrences  -I – case-insensitive
  • 8. tr • The “tr” command is used to translate characters. It uses two sets of characters, given as command arguments and converts them on a char-to-char basis. Is can also:  Converts letter cases; upper to lower and vice-versa.  Recognizes special characters, such as n (newline)  Cannot open files; can only use data from pipes or redirections from within files. • Syntax:  tr [options] charter-list1 charter-list2 < [file] • Options:  -d – delete all characters appearing in “chars1”  -s - replace instances of repeated characters with a single character.  -cd – delete all characters that are NOT in “chars1”
  • 9. tail • The “tail” command prints the end of a file • Syntax:  tail [options] [filename(s)] • Options:  -n+N print the last N lines (default is 10)  -n-N print the entire file starting from line N  -f follow mode. tail will stay active and update on each new line to the file
  • 10. head • The “head” command prints the start of a file • Syntax:  head [options] [filename(s)] • Options:  -n+N print the first N lines (default is 10)  -n-N print the entire file until the Nth line

Editor's Notes

  • #6: Exrcise: Print out a list of users and their home directories
  • #7: Exrcise: sort users by Group ID. again, man sort
  • #11: Exercise: Use two terminals to examine the ‘tail -f’ option