SlideShare a Scribd company logo
1 of 13
Introduction to Unix and OS
Module 3
sort, uniq, tr, grep and sed
Dr. Girisha G S
Dept. of CSE
SoE,DSU, Bengaluru
1
Agenda
- sort
- uniq
- Tr
- grep
- sed
2
3
sort – ordering a file
- sort command sorts the contents of the text file line by line
Syntax:
sort [options] [file]
options
-n sort numerically
-r reverse the order of the sort
-t char uses delimiter character to identify fields
-k n sort on the nth field
-k m,n starts sort on the m filed & ends sort on nth filed
-u removes repeated line
-o flname places output in the file flname
4
Example: consider the following file
$ cat file1.txt
Zimbabwe
Serbia
Norway
Australia
• Sort the file file1.txt
$ sort file1.txt
Australia
Norway
Serbia
Zimbabwe
• Numeric sorting
Example: sort the file marks.txt
$ cat marks.txt
22
33
11
77
55
$ sort -n marks.txt
11
22
33
55
77
5
Example : Sort a colon delimited text file on second field
$ cat names.txt
Alex Jason:200:Sales
Emma Thomas:100:Marketing
Madison Randy:300:Product Development
Nisha Singh:500:Sales
Sanjay Gupta:400:Support
$ sort -t: -k 2 names.txt
Emma Thomas:100:Marketing
Alex Jason:200:Sales
Madison Randy:300:Product Development
Sanjay Gupta:400:Support
Nisha Singh:500:Sales
6
uniq command – locate repeated and non repeated lines
- uniq command reports or filters out the repeated lines in a file
Syntax:
uniq [option] filename
Example : consider the following example.txt file
$ cat example.txt
unix operating system
unix operating system
unix dedicated server
linux dedicated server
• To suppress duplicate lines
$ uniq example.txt
unix operating system
unix dedicated server
linux dedicated server
options
-u lists only lines that are unique
-d lists only the lines that are duplicate
-c counts the frequency of occurences
7
tr command – translating characters
- the tr command automatically translates (substitutes, or maps) one set
of characters to another.
- Input always comes from standard input
- Arguments don’t include filenames
Syntax:
tr [options] "set1" "set2"
Example : Convert lower case letters to upper case
$ echo "linux dedicated server" | tr a-z A-Z
LINUX DEDICATED SERVER
options
-d deletes a specified range of characters
-s squeezes multiple occurrences of a character into a single word
Example: delete specific characters
$ echo "Welcome To GeeksforGeeks" | tr -d ‘W‘
elcome To GeeksforGeeks
8
Example: convert multiple continuous spaces with a single space
$ echo 'too many spaces here' | tr -s '[:space:]'
too many spaces here
9
Filters Using Regular Expression : grep and sed
grep – searching for a pattern
- It scans the file / input for a pattern and displays lines containing the pattern
Syntax:
grep options pattern filename(s)
Example: To demonstrate this, let’s create a text file welcome.txt. Display
lines containing the string “Linux” from the file welcome.txt
$ cat welcome.txt
Welcome to Linux !
Linux is a free and open source Operating system that is mostly used by
developers and in production servers for hosting crucial components such as web
and database servers. Linux has also made a name for itself in PCs.
Beginners looking to experiment with Linux can get started with friendlier linux
distributions such as Ubuntu, Mint, Fedora and Elementary OS.
$ grep “Linux” welcome.txt
Welcome to Linux !
Linux is a free and open source Operating system that is mostly used by
and database servers. Linux has also made a name for itself in PCs.
Beginners looking to experiment with Linux can get started with friendlier linux
10
Example 2: Display lines containing the string “sales “ from the file emp.lst
$ cat emp.lst
2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000
9876 | jai sharma | director | production | 12/03/50 | 7000
5678 | sumit chakrobarty | d.g.m. | marketing | 19/04/43 | 6000
2365 | barun sengupta | director | personnel | 11/05/47 | 7800
5423 | n.k.gupta | chairman | admin | 30/08/56 | 5400
1006 | chanchal singhvi | director | sales | 03/09/38 | 6700
6213 | karuna ganguly | g.m. | accounts | 05/06/62 | 6300
1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600
4290 | jayant choudhury | executive | production | 07/09/50 | 6000
2476 | anil aggarwal | manager | sales | 01/05/59 | 5000
6521 | lalit chowdury | directir | marketing | 26/09/45 | 8200
3212 | shyam saksena | d.g.m. | accounts | 12/12/55 | 6000
3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500
2345 | j. b. sexena | g.m. | marketing | 12/03/45 | 8000
0110 | v.k.agrawal | g.m.| marketing | 31/12/40 | 9000
$ grep “sales” emp.lst
2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000
1006 | chanchal singhvi | director | sales | 03/09/38 | 6700
1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600
2476 | anil aggarwal | manager | sales | 01/05/59 | 5000
11
grep options
-i ignores case for matching
Example : Display lines containing the string “agarwal “ from the file emp.lst
$ cat emp.lst
2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000
9876 | jai sharma | director | production | 12/03/50 | 7000
5678 | sumit chakrobarty | d.g.m. | marketing | 19/04/43 | 6000
2365 | barun sengupta | director | personnel | 11/05/47 | 7800
5423 | n.k.gupta | chairman | admin | 30/08/56 | 5400
1006 | chanchal singhvi | director | sales | 03/09/38 | 6700
6213 | karuna ganguly | g.m. | accounts | 05/06/62 | 6300
1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600
4290 | jayant choudhury | executive | production | 07/09/50 | 6000
2476 | anil aggarwal | manager | sales | 01/05/59 | 5000
6521 | lalit chowdury | directir | marketing | 26/09/45 | 8200
3212 | shyam saksena | d.g.m. | accounts | 12/12/55 | 6000
3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500
2345 | j. b. sexena | g.m. | marketing | 12/03/45 | 8000
0110 | v.k.agrawal | g.m.| marketing | 31/12/40 | 9000
$ grep -i “agarwal” emp.lst
3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500
12
-v Does not display lines matching the expression, select non matching lines
Example: $ grep -v “director” emp.lst
2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000
5678 | sumit chakrobarty | d.g.m. | marketing | 19/04/43 | 6000
5423 | n.k.gupta | chairman | admin | 30/08/56 | 5400
6213 | karuna ganguly | g.m. | accounts | 05/06/62 | 6300
1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600
4290 | jayant choudhury | executive | production | 07/09/50 | 6000
2476 | anil aggarwal | manager | sales | 01/05/59 | 5000
6521 | lalit chowdury | directir | marketing | 26/09/45 | 8200
3212 | shyam saksena | d.g.m. | accounts | 12/12/55 | 6000
3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500
2345 | j. b. sexena | g.m. | marketing | 12/03/45 | 8000
0110 | v.k.agrawal | g.m.| marketing | 31/12/40 | 9000
13
-n displays line numbers along with lines
-c displays count of number of occurrences
-l displays list of filenames only
-e exp specifies expression with this option
-E treats pattern as an extended RE
Examples:
$ grep -n “marketing” emp.lst
$ grep -c “director” emp.lst
$ grep –l “manager” *.lst
$ grep -e “agarwal” –e “aggarwal” -e “agrawal” emp.lst

More Related Content

What's hot

Postgresql 12 streaming replication hol
Postgresql 12 streaming replication holPostgresql 12 streaming replication hol
Postgresql 12 streaming replication holVijay Kumar N
 
Management file and directory in linux
Management file and directory in linuxManagement file and directory in linux
Management file and directory in linuxZkre Saleh
 
User Administration in Linux
User Administration in LinuxUser Administration in Linux
User Administration in LinuxSAMUEL OJO
 
Query evaluation and optimization
Query evaluation and optimizationQuery evaluation and optimization
Query evaluation and optimizationlavanya marichamy
 
Chapter 13. Trends and Research Frontiers in Data Mining.ppt
Chapter 13. Trends and Research Frontiers in Data Mining.pptChapter 13. Trends and Research Frontiers in Data Mining.ppt
Chapter 13. Trends and Research Frontiers in Data Mining.pptSubrata Kumer Paul
 
Code Once Use Often with Declarative Data Pipelines
Code Once Use Often with Declarative Data PipelinesCode Once Use Often with Declarative Data Pipelines
Code Once Use Often with Declarative Data PipelinesDatabricks
 
Customizing the look and-feel of DSpace
Customizing the look and-feel of DSpaceCustomizing the look and-feel of DSpace
Customizing the look and-feel of DSpaceBharat Chaudhari
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structureSreenatha Reddy K R
 
CKAN - the open source data portal platform
CKAN - the open source data portal platformCKAN - the open source data portal platform
CKAN - the open source data portal platformMaurizio Napolitano
 
Big data visualization
Big data visualizationBig data visualization
Big data visualizationAnurag Gupta
 
How to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-SourceHow to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-SourceDatabricks
 
Data mining tools (R , WEKA, RAPID MINER, ORANGE)
Data mining tools (R , WEKA, RAPID MINER, ORANGE)Data mining tools (R , WEKA, RAPID MINER, ORANGE)
Data mining tools (R , WEKA, RAPID MINER, ORANGE)Krishna Petrochemicals
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scriptingVIKAS TIWARI
 
Introduction to Data Mining
Introduction to Data Mining Introduction to Data Mining
Introduction to Data Mining Sushil Kulkarni
 

What's hot (20)

Postgresql 12 streaming replication hol
Postgresql 12 streaming replication holPostgresql 12 streaming replication hol
Postgresql 12 streaming replication hol
 
Management file and directory in linux
Management file and directory in linuxManagement file and directory in linux
Management file and directory in linux
 
Segmentation
SegmentationSegmentation
Segmentation
 
User Administration in Linux
User Administration in LinuxUser Administration in Linux
User Administration in Linux
 
Query evaluation and optimization
Query evaluation and optimizationQuery evaluation and optimization
Query evaluation and optimization
 
Chapter 13. Trends and Research Frontiers in Data Mining.ppt
Chapter 13. Trends and Research Frontiers in Data Mining.pptChapter 13. Trends and Research Frontiers in Data Mining.ppt
Chapter 13. Trends and Research Frontiers in Data Mining.ppt
 
Code Once Use Often with Declarative Data Pipelines
Code Once Use Often with Declarative Data PipelinesCode Once Use Often with Declarative Data Pipelines
Code Once Use Often with Declarative Data Pipelines
 
Customizing the look and-feel of DSpace
Customizing the look and-feel of DSpaceCustomizing the look and-feel of DSpace
Customizing the look and-feel of DSpace
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
CKAN - the open source data portal platform
CKAN - the open source data portal platformCKAN - the open source data portal platform
CKAN - the open source data portal platform
 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
 
Big data visualization
Big data visualizationBig data visualization
Big data visualization
 
How to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-SourceHow to Build a ML Platform Efficiently Using Open-Source
How to Build a ML Platform Efficiently Using Open-Source
 
Data mining tools (R , WEKA, RAPID MINER, ORANGE)
Data mining tools (R , WEKA, RAPID MINER, ORANGE)Data mining tools (R , WEKA, RAPID MINER, ORANGE)
Data mining tools (R , WEKA, RAPID MINER, ORANGE)
 
Cron
CronCron
Cron
 
Data Extraction
Data ExtractionData Extraction
Data Extraction
 
An Introduction To Linux
An Introduction To LinuxAn Introduction To Linux
An Introduction To Linux
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Hadoop
HadoopHadoop
Hadoop
 
Introduction to Data Mining
Introduction to Data Mining Introduction to Data Mining
Introduction to Data Mining
 

More from Dr. Girish GS

unix- the process states, zombies, running jobs in background
unix-  the process states, zombies, running jobs in backgroundunix-  the process states, zombies, running jobs in background
unix- the process states, zombies, running jobs in backgroundDr. Girish GS
 
Customizing the unix environment
Customizing the unix environmentCustomizing the unix environment
Customizing the unix environmentDr. Girish GS
 
File systems and inodes
File systems and inodesFile systems and inodes
File systems and inodesDr. Girish GS
 
Basic regular expression, extended regular expression
Basic regular expression, extended regular expressionBasic regular expression, extended regular expression
Basic regular expression, extended regular expressionDr. Girish GS
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamDr. Girish GS
 
Logic instructions part 1
Logic instructions part 1Logic instructions part 1
Logic instructions part 1Dr. Girish GS
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructionsDr. Girish GS
 
Bcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructionsBcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructionsDr. Girish GS
 
Ascii arithmetic instructions
Ascii arithmetic instructionsAscii arithmetic instructions
Ascii arithmetic instructionsDr. Girish GS
 
Program control instructions
Program control instructionsProgram control instructions
Program control instructionsDr. Girish GS
 

More from Dr. Girish GS (14)

Unix- the process
Unix-  the processUnix-  the process
Unix- the process
 
unix- the process states, zombies, running jobs in background
unix-  the process states, zombies, running jobs in backgroundunix-  the process states, zombies, running jobs in background
unix- the process states, zombies, running jobs in background
 
Unix - Filters
Unix - FiltersUnix - Filters
Unix - Filters
 
Customizing the unix environment
Customizing the unix environmentCustomizing the unix environment
Customizing the unix environment
 
File systems and inodes
File systems and inodesFile systems and inodes
File systems and inodes
 
Basic regular expression, extended regular expression
Basic regular expression, extended regular expressionBasic regular expression, extended regular expression
Basic regular expression, extended regular expression
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
 
Logic instructions part 1
Logic instructions part 1Logic instructions part 1
Logic instructions part 1
 
Bcd arithmetic instructions
Bcd arithmetic instructionsBcd arithmetic instructions
Bcd arithmetic instructions
 
Bcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructionsBcd and ascii arithmetic instructions
Bcd and ascii arithmetic instructions
 
Ascii arithmetic instructions
Ascii arithmetic instructionsAscii arithmetic instructions
Ascii arithmetic instructions
 
Rotate instructions
Rotate instructionsRotate instructions
Rotate instructions
 
Program control instructions
Program control instructionsProgram control instructions
Program control instructions
 
Memory interface
Memory interfaceMemory interface
Memory interface
 

Recently uploaded

Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Recently uploaded (20)

Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 

unix- Sort, uniq,tr,grep

  • 1. Introduction to Unix and OS Module 3 sort, uniq, tr, grep and sed Dr. Girisha G S Dept. of CSE SoE,DSU, Bengaluru 1
  • 2. Agenda - sort - uniq - Tr - grep - sed 2
  • 3. 3 sort – ordering a file - sort command sorts the contents of the text file line by line Syntax: sort [options] [file] options -n sort numerically -r reverse the order of the sort -t char uses delimiter character to identify fields -k n sort on the nth field -k m,n starts sort on the m filed & ends sort on nth filed -u removes repeated line -o flname places output in the file flname
  • 4. 4 Example: consider the following file $ cat file1.txt Zimbabwe Serbia Norway Australia • Sort the file file1.txt $ sort file1.txt Australia Norway Serbia Zimbabwe • Numeric sorting Example: sort the file marks.txt $ cat marks.txt 22 33 11 77 55 $ sort -n marks.txt 11 22 33 55 77
  • 5. 5 Example : Sort a colon delimited text file on second field $ cat names.txt Alex Jason:200:Sales Emma Thomas:100:Marketing Madison Randy:300:Product Development Nisha Singh:500:Sales Sanjay Gupta:400:Support $ sort -t: -k 2 names.txt Emma Thomas:100:Marketing Alex Jason:200:Sales Madison Randy:300:Product Development Sanjay Gupta:400:Support Nisha Singh:500:Sales
  • 6. 6 uniq command – locate repeated and non repeated lines - uniq command reports or filters out the repeated lines in a file Syntax: uniq [option] filename Example : consider the following example.txt file $ cat example.txt unix operating system unix operating system unix dedicated server linux dedicated server • To suppress duplicate lines $ uniq example.txt unix operating system unix dedicated server linux dedicated server options -u lists only lines that are unique -d lists only the lines that are duplicate -c counts the frequency of occurences
  • 7. 7 tr command – translating characters - the tr command automatically translates (substitutes, or maps) one set of characters to another. - Input always comes from standard input - Arguments don’t include filenames Syntax: tr [options] "set1" "set2" Example : Convert lower case letters to upper case $ echo "linux dedicated server" | tr a-z A-Z LINUX DEDICATED SERVER options -d deletes a specified range of characters -s squeezes multiple occurrences of a character into a single word Example: delete specific characters $ echo "Welcome To GeeksforGeeks" | tr -d ‘W‘ elcome To GeeksforGeeks
  • 8. 8 Example: convert multiple continuous spaces with a single space $ echo 'too many spaces here' | tr -s '[:space:]' too many spaces here
  • 9. 9 Filters Using Regular Expression : grep and sed grep – searching for a pattern - It scans the file / input for a pattern and displays lines containing the pattern Syntax: grep options pattern filename(s) Example: To demonstrate this, let’s create a text file welcome.txt. Display lines containing the string “Linux” from the file welcome.txt $ cat welcome.txt Welcome to Linux ! Linux is a free and open source Operating system that is mostly used by developers and in production servers for hosting crucial components such as web and database servers. Linux has also made a name for itself in PCs. Beginners looking to experiment with Linux can get started with friendlier linux distributions such as Ubuntu, Mint, Fedora and Elementary OS. $ grep “Linux” welcome.txt Welcome to Linux ! Linux is a free and open source Operating system that is mostly used by and database servers. Linux has also made a name for itself in PCs. Beginners looking to experiment with Linux can get started with friendlier linux
  • 10. 10 Example 2: Display lines containing the string “sales “ from the file emp.lst $ cat emp.lst 2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000 9876 | jai sharma | director | production | 12/03/50 | 7000 5678 | sumit chakrobarty | d.g.m. | marketing | 19/04/43 | 6000 2365 | barun sengupta | director | personnel | 11/05/47 | 7800 5423 | n.k.gupta | chairman | admin | 30/08/56 | 5400 1006 | chanchal singhvi | director | sales | 03/09/38 | 6700 6213 | karuna ganguly | g.m. | accounts | 05/06/62 | 6300 1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600 4290 | jayant choudhury | executive | production | 07/09/50 | 6000 2476 | anil aggarwal | manager | sales | 01/05/59 | 5000 6521 | lalit chowdury | directir | marketing | 26/09/45 | 8200 3212 | shyam saksena | d.g.m. | accounts | 12/12/55 | 6000 3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500 2345 | j. b. sexena | g.m. | marketing | 12/03/45 | 8000 0110 | v.k.agrawal | g.m.| marketing | 31/12/40 | 9000 $ grep “sales” emp.lst 2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000 1006 | chanchal singhvi | director | sales | 03/09/38 | 6700 1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600 2476 | anil aggarwal | manager | sales | 01/05/59 | 5000
  • 11. 11 grep options -i ignores case for matching Example : Display lines containing the string “agarwal “ from the file emp.lst $ cat emp.lst 2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000 9876 | jai sharma | director | production | 12/03/50 | 7000 5678 | sumit chakrobarty | d.g.m. | marketing | 19/04/43 | 6000 2365 | barun sengupta | director | personnel | 11/05/47 | 7800 5423 | n.k.gupta | chairman | admin | 30/08/56 | 5400 1006 | chanchal singhvi | director | sales | 03/09/38 | 6700 6213 | karuna ganguly | g.m. | accounts | 05/06/62 | 6300 1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600 4290 | jayant choudhury | executive | production | 07/09/50 | 6000 2476 | anil aggarwal | manager | sales | 01/05/59 | 5000 6521 | lalit chowdury | directir | marketing | 26/09/45 | 8200 3212 | shyam saksena | d.g.m. | accounts | 12/12/55 | 6000 3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500 2345 | j. b. sexena | g.m. | marketing | 12/03/45 | 8000 0110 | v.k.agrawal | g.m.| marketing | 31/12/40 | 9000 $ grep -i “agarwal” emp.lst 3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500
  • 12. 12 -v Does not display lines matching the expression, select non matching lines Example: $ grep -v “director” emp.lst 2233 | a.k.shukla | g.m | sales | 12/12/52 | 6000 5678 | sumit chakrobarty | d.g.m. | marketing | 19/04/43 | 6000 5423 | n.k.gupta | chairman | admin | 30/08/56 | 5400 6213 | karuna ganguly | g.m. | accounts | 05/06/62 | 6300 1265 | s.n. dasgupta | manager | sales | 12/09/63 | 5600 4290 | jayant choudhury | executive | production | 07/09/50 | 6000 2476 | anil aggarwal | manager | sales | 01/05/59 | 5000 6521 | lalit chowdury | directir | marketing | 26/09/45 | 8200 3212 | shyam saksena | d.g.m. | accounts | 12/12/55 | 6000 3564 | sudhir agarwal | executive | personnel | 06/07/47 | 7500 2345 | j. b. sexena | g.m. | marketing | 12/03/45 | 8000 0110 | v.k.agrawal | g.m.| marketing | 31/12/40 | 9000
  • 13. 13 -n displays line numbers along with lines -c displays count of number of occurrences -l displays list of filenames only -e exp specifies expression with this option -E treats pattern as an extended RE Examples: $ grep -n “marketing” emp.lst $ grep -c “director” emp.lst $ grep –l “manager” *.lst $ grep -e “agarwal” –e “aggarwal” -e “agrawal” emp.lst

Editor's Notes

  1. We use commands that filter data to select only the portion of data that we wish to view or operate on. t can be used to process information in powerful ways such as restructuring output to generate useful reports, modifying text in files and many other system administration tasks.
  2. The sort tool will sort lines alphabetically by default. Sort command compares the first character in every line of file to implement the specified order. If the first character of the 2 line are identical, the command compare the second character
  3. When we concatenate or merge files, we will face the problem of duplicate entries creeping in. we saw how sort removes them with the –u option. UNIX offers a special tool to handle these lines – the uniq command. In simple words, uniq is the tool that helps to detect the adjacent duplicate lines and also deletes the duplicate lines. Uniq command in unix or linux system is used to suppress the duplicate lines from a file
  4. It can be used to convert uppercase to lowercase, squeeze repeating characters and deleting characters.
  5. It can be used for pattern matching Grep searches a file and displays the line containing the pattern . Grep searches for patterns in one or more filenames or the stad input if no filename is specified The grep command is used to search text
  6. -e match multiple pattern