SlideShare una empresa de Scribd logo
1 de 10
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
 
15 practical grep command examples in linux
15 practical grep command examples in linux15 practical grep command examples in linux
15 practical grep command examples in linux
 
Grep
GrepGrep
Grep
 
Spsl II unit
Spsl   II unitSpsl   II unit
Spsl II unit
 
Unix / Linux Command Reference
Unix / Linux Command ReferenceUnix / Linux Command Reference
Unix / Linux Command Reference
 
Pipes and filters
Pipes and filtersPipes and filters
Pipes and filters
 
Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014Unix Command-Line Cheat Sheet BTI2014
Unix Command-Line Cheat Sheet BTI2014
 
2
22
2
 
Regular Expressions grep and egrep
Regular Expressions grep and egrepRegular Expressions grep and egrep
Regular Expressions grep and egrep
 
Unix Basics Commands
Unix Basics CommandsUnix Basics Commands
Unix Basics Commands
 
File management in C++
File management in C++File management in C++
File management in C++
 
Learning Grep
Learning GrepLearning Grep
Learning Grep
 
Unit3 browsing the filesystem
Unit3 browsing the filesystemUnit3 browsing the filesystem
Unit3 browsing the filesystem
 
Linux
LinuxLinux
Linux
 
file management in c language
file management in c languagefile management in c language
file management in c language
 
Programming in C Session 4
Programming in C Session 4Programming in C Session 4
Programming in C Session 4
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
 

Similar a 08 text processing_tools

Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing toolsroot_fibo
 
101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressionsAcácio Oliveira
 
Commands and shell programming (3)
Commands and shell programming (3)Commands and shell programming (3)
Commands and shell programming (3)christ university
 
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCAAARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCAAaravNayan
 
Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Ahmed El-Arabawy
 
workshop_1.ppt
workshop_1.pptworkshop_1.ppt
workshop_1.ppthazhamina
 
1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdfamaresh6333
 
intro unix/linux 05
intro unix/linux 05intro unix/linux 05
intro unix/linux 05duquoi
 
3.7 search text files using regular expressions
3.7 search text files using regular expressions3.7 search text files using regular expressions
3.7 search text files using regular expressionsAcácio Oliveira
 
Unix Trainning Doc.pptx
Unix Trainning Doc.pptxUnix Trainning Doc.pptx
Unix Trainning Doc.pptxKalpeshRaut7
 
Filters & Vi Editor
Filters & Vi EditorFilters & Vi Editor
Filters & Vi EditorBIT DURG
 
Basic Linux Commands
Basic Linux CommandsBasic Linux Commands
Basic Linux CommandsBIT DURG
 

Similar a 08 text processing_tools (20)

Scripting and the shell in LINUX
Scripting and the shell in LINUXScripting and the shell in LINUX
Scripting and the shell in LINUX
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing tools
 
grep.1.pdf
grep.1.pdfgrep.1.pdf
grep.1.pdf
 
grep.1.pdf
grep.1.pdfgrep.1.pdf
grep.1.pdf
 
Group13
Group13Group13
Group13
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
Linux
LinuxLinux
Linux
 
101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions101 3.7 search text files using regular expressions
101 3.7 search text files using regular expressions
 
Commands and shell programming (3)
Commands and shell programming (3)Commands and shell programming (3)
Commands and shell programming (3)
 
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCAAARAV NAYAN OPERATING SYSTEM LABORATORY PCA
AARAV NAYAN OPERATING SYSTEM LABORATORY PCA
 
Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions Course 102: Lecture 13: Regular Expressions
Course 102: Lecture 13: Regular Expressions
 
workshop_1.ppt
workshop_1.pptworkshop_1.ppt
workshop_1.ppt
 
1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf1) List currently running jobsANS) see currently runningcommand.pdf
1) List currently running jobsANS) see currently runningcommand.pdf
 
Lecture_4.pdf
Lecture_4.pdfLecture_4.pdf
Lecture_4.pdf
 
linux OS.pptx
linux OS.pptxlinux OS.pptx
linux OS.pptx
 
intro unix/linux 05
intro unix/linux 05intro unix/linux 05
intro unix/linux 05
 
3.7 search text files using regular expressions
3.7 search text files using regular expressions3.7 search text files using regular expressions
3.7 search text files using regular expressions
 
Unix Trainning Doc.pptx
Unix Trainning Doc.pptxUnix Trainning Doc.pptx
Unix Trainning Doc.pptx
 
Filters & Vi Editor
Filters & Vi EditorFilters & Vi Editor
Filters & Vi Editor
 
Basic Linux Commands
Basic Linux CommandsBasic Linux Commands
Basic Linux Commands
 

Más de Shay Cohen

Linux Performance Tunning Memory
Linux Performance Tunning MemoryLinux Performance Tunning Memory
Linux Performance Tunning MemoryShay Cohen
 
Linux Performance Tunning Kernel
Linux Performance Tunning KernelLinux Performance Tunning Kernel
Linux Performance Tunning KernelShay Cohen
 
Linux Performance Tunning introduction
Linux Performance Tunning introductionLinux Performance Tunning introduction
Linux Performance Tunning introductionShay Cohen
 
chroot and SELinux
chroot and SELinuxchroot and SELinux
chroot and SELinuxShay Cohen
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/CoreShay Cohen
 
Infra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automationInfra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automationShay Cohen
 
14 network tools
14 network tools14 network tools
14 network toolsShay Cohen
 
13 process management
13 process management13 process management
13 process managementShay Cohen
 
12 linux archiving tools
12 linux archiving tools12 linux archiving tools
12 linux archiving toolsShay Cohen
 
11 linux filesystem copy
11 linux filesystem copy11 linux filesystem copy
11 linux filesystem copyShay Cohen
 
10 finding files
10 finding files10 finding files
10 finding filesShay Cohen
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editorShay Cohen
 
06 users groups_and_permissions
06 users groups_and_permissions06 users groups_and_permissions
06 users groups_and_permissionsShay Cohen
 
05 standard io_and_pipes
05 standard io_and_pipes05 standard io_and_pipes
05 standard io_and_pipesShay Cohen
 
04 using and_configuring_bash
04 using and_configuring_bash04 using and_configuring_bash
04 using and_configuring_bashShay Cohen
 
03 browsing the filesystem
03 browsing the filesystem03 browsing the filesystem
03 browsing the filesystemShay Cohen
 
02 linux desktop usage
02 linux desktop usage02 linux desktop usage
02 linux desktop usageShay Cohen
 
09 string processing_with_regex copy
09 string processing_with_regex copy09 string processing_with_regex copy
09 string processing_with_regex copyShay Cohen
 
01 linux history overview
01 linux history overview01 linux history overview
01 linux history overviewShay Cohen
 

Más de Shay Cohen (19)

Linux Performance Tunning Memory
Linux Performance Tunning MemoryLinux Performance Tunning Memory
Linux Performance Tunning Memory
 
Linux Performance Tunning Kernel
Linux Performance Tunning KernelLinux Performance Tunning Kernel
Linux Performance Tunning Kernel
 
Linux Performance Tunning introduction
Linux Performance Tunning introductionLinux Performance Tunning introduction
Linux Performance Tunning introduction
 
chroot and SELinux
chroot and SELinuxchroot and SELinux
chroot and SELinux
 
Linux Internals - Kernel/Core
Linux Internals - Kernel/CoreLinux Internals - Kernel/Core
Linux Internals - Kernel/Core
 
Infra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automationInfra / Cont delivery - 3rd party automation
Infra / Cont delivery - 3rd party automation
 
14 network tools
14 network tools14 network tools
14 network tools
 
13 process management
13 process management13 process management
13 process management
 
12 linux archiving tools
12 linux archiving tools12 linux archiving tools
12 linux archiving tools
 
11 linux filesystem copy
11 linux filesystem copy11 linux filesystem copy
11 linux filesystem copy
 
10 finding files
10 finding files10 finding files
10 finding files
 
07 vi text_editor
07 vi text_editor07 vi text_editor
07 vi text_editor
 
06 users groups_and_permissions
06 users groups_and_permissions06 users groups_and_permissions
06 users groups_and_permissions
 
05 standard io_and_pipes
05 standard io_and_pipes05 standard io_and_pipes
05 standard io_and_pipes
 
04 using and_configuring_bash
04 using and_configuring_bash04 using and_configuring_bash
04 using and_configuring_bash
 
03 browsing the filesystem
03 browsing the filesystem03 browsing the filesystem
03 browsing the filesystem
 
02 linux desktop usage
02 linux desktop usage02 linux desktop usage
02 linux desktop usage
 
09 string processing_with_regex copy
09 string processing_with_regex copy09 string processing_with_regex copy
09 string processing_with_regex copy
 
01 linux history overview
01 linux history overview01 linux history overview
01 linux history overview
 

Último

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Último (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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

Notas del editor

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