SlideShare uma empresa Scribd logo
1 de 13
UNIX - sed



       Non-Interactive
       Stream Editor



             Presentation By

                       Nihar R Paital
Introduction

   Developer       : Lee E. McMahon

   Developed during: 1973-1974

   Developed at    : Bell Labs

   Category        : UNIX Utility

   Supported by    : All UNIX flavors

                                         Nihar R Paital
For practicing the commands please create a file
test1.txt and copy the below contents into test1.txt

 s
s
sprint Telecom
3sprint Telecom
sprint

we are working in sprint

IBM
0IBM

nihar,rahulk,sam,papau
We are working in IBM
6We are working in IBM
nihar:rahulk:sam:papau
nihar,rahulk,sam
We are working in IBM India


                                        Nihar R Paital
It performs basic text transformation on an input
stream ( A file / input from a pipeline )


 Transformation using input file
$ sed -e ‘s/oldval/newval/g’ inputFile > outputFile
Example:
$ sed -e ‘s/mumbai/pune/g’ stud.txt > stud.txt.bak

 Transformation using a filter in a pipeline
$ generate_data | sed -e ‘s/oldval/newval/g’
Example:
$ cat stud.txt | sed -e ‘s/mumbai/pune/g’ > stud.txt.bak
                                            Nihar R Paital
Main options of sed


   p - print

   d - delete

   s - substitute


                      Nihar R Paital
Below special characters have vital role using sed



  Character    Description

     ^        Matches the beginning of the line.
     $        Matches the end of the line.
     .        Matches any single character.
     *        Will match zero or more occurrences of
               the previous character.
     []       Matches all the characters inside the [ ].
                                           Nihar R Paital
Examples (^                Matches the beginning of the line)


$ sed '/^sprint/p' test1.txt
   Will Print the lines 2 times which contain sprint as a first ward of
   the line

$ sed -n '/^sprint/p' test1.txt
   Will Print the lines which contain sprint as a first ward of the line

$ sed 's/^sprint/IBM INDIA/g' test1.txt
   Will Substitute “IBM INDIA” in place of “sprint” if it appears at
   beginning of line.

$ sed '/^sprint/d' test1.txt
   Will delete all lines containing “sprint” as a first word R Paital line.
                                                         Nihar of the
Example ($                   Matches the end of the line)


$ sed '/sprint$/p' test1.txt
   Will Print the lines 2 times which contain sprint as a last ward of the
   line

$ sed -n '/sprint$/p' test1.txt
   Will Print the lines which contain sprint as a first ward of the line

$ sed 's/sprint$/IBM INDIA/g' test1.txt
   Will Substitute “IBM INDIA” in place of “sprint” if it appears at end of
   line.

$ sed '/sprint$/d' test1.txt
   Will delete all lines containing “sprint” as a first word of the line.

$ sed -n '/^$/p' test1.txt
   Will delete all blank lines                                Nihar R Paital
Example (.                Matches any single character)




$ sed -n '/./p' test1.txt
   It will print the lines which at least contains a single Character.
   It can be used for ignoring all blank lines.

$ sed -n '/../p' test1.txt
   It will print the lines which at least contains a single Character.

$ sed -n '/IB./p' test1.txt
   It will print the lines which at least contains a single Character
   after the String IB”.

                                                      Nihar R Paital
Example (*                      Will match zero or more occurrences of
                                the previous character)


$ sed -n '/ */p' test1.txt
   It will print all lines like “cat test1.txt”

$ sed -n '/ */p' test1.txt
   It will print the lines which contains at leaset 2 characters except
   delimited lines.

$ sed -n '/.*,.*,.*/p' test1.txt
   It will print the lines where the strings are separated by at least 3
   commas(,).

$ sed -n '/.*,.*,.*/p' test1.txt | cut -d"," -f 3
   It will print the 3rd filed of the lines where the strings are separated by
   at least 3 commas(,).

$ sed -n '/We*/p' test1.txt                                    Nihar R Paital
   It will print all the lines where at least the string “We” is present
Example ([ ]              Matches all the characters inside
                          the [ ])

$ sed -n '/[abc]/p' test1.txt
   This will print all the lines which contains either a or b or c as
   part of the line.

$ sed -n '/^[0-9]/p' test1.txt
   This will print all the lines which contains the digit 0 to 9 as part
   of line

$ sed -n '/^[^0-9]/p' test1.tx
   This will print all the lines which does not contains the digit 0 to
   9 as part of line

$ sed 's/[abc]/we/g' test1.txt
   This will replace the string “WE” where either a or b or c is
   present as part of the line.                      Nihar R Paital
Sed – Line number manipulation

1 first line
$ last line
m,n m to n line
Example:
$ sed -n '3,7p' test1.txt
It will print the lines from 3 to 7
$ sed -n 'n;n;n;p' test1.txt ( every 4th line )
It will print every 4th line of the file

                                             Nihar R Paital
Nihar R Paital

Mais conteúdo relacionado

Mais procurados

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 linuxTeja Bheemanapally
 
2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functionsfuturespective
 
Ad hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsAd hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsPhilip Schwarz
 
Objective C for Samurais
Objective C for SamuraisObjective C for Samurais
Objective C for Samuraisrafaecheve
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regexJalpesh Vasa
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
Regular Expression
Regular ExpressionRegular Expression
Regular ExpressionLambert Lum
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record.toster
 
Strings in Python
Strings in PythonStrings in Python
Strings in Pythonnitamhaske
 

Mais procurados (20)

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
 
Javascript ch6
Javascript ch6Javascript ch6
Javascript ch6
 
2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functions
 
Lecture2 B
Lecture2 BLecture2 B
Lecture2 B
 
Ad hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsAd hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and Cats
 
Objective C for Samurais
Objective C for SamuraisObjective C for Samurais
Objective C for Samurais
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
 
3.2 javascript regex
3.2 javascript regex3.2 javascript regex
3.2 javascript regex
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Functions
FunctionsFunctions
Functions
 
Generics With Swift
Generics With SwiftGenerics With Swift
Generics With Swift
 
Awk programming
Awk programming Awk programming
Awk programming
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
Attributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active recordAttributes Unwrapped: Lessons under the surface of active record
Attributes Unwrapped: Lessons under the surface of active record
 
5. string
5. string5. string
5. string
 
Strings in Python
Strings in PythonStrings in Python
Strings in Python
 
C workshop day 7
C workshop day 7C workshop day 7
C workshop day 7
 
Subroutines
SubroutinesSubroutines
Subroutines
 

Destaque (20)

Unix
UnixUnix
Unix
 
Unix command-line tools
Unix command-line toolsUnix command-line tools
Unix command-line tools
 
Sed & awk the dynamic duo
Sed & awk   the dynamic duoSed & awk   the dynamic duo
Sed & awk the dynamic duo
 
Grep
GrepGrep
Grep
 
Learning Grep
Learning GrepLearning Grep
Learning Grep
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
 
Awk Unix Utility Explained
Awk Unix Utility ExplainedAwk Unix Utility Explained
Awk Unix Utility Explained
 
Unix day4 v1.3
Unix day4 v1.3Unix day4 v1.3
Unix day4 v1.3
 
What Linux is what you should also have on your computer.
What Linux is what you should also have on your computer.What Linux is what you should also have on your computer.
What Linux is what you should also have on your computer.
 
Unix day2 v1.3
Unix day2 v1.3Unix day2 v1.3
Unix day2 v1.3
 
Unix day3 v1.3
Unix day3 v1.3Unix day3 v1.3
Unix day3 v1.3
 
Unix
UnixUnix
Unix
 
Testingtechniques And Strategy
Testingtechniques And StrategyTestingtechniques And Strategy
Testingtechniques And Strategy
 
Linux 101 Exploring Linux OS
Linux 101 Exploring Linux OSLinux 101 Exploring Linux OS
Linux 101 Exploring Linux OS
 
Advanced Shell Scripting
Advanced Shell ScriptingAdvanced Shell Scripting
Advanced Shell Scripting
 
Presentation of awk
Presentation of awkPresentation of awk
Presentation of awk
 
unix crontab basics
unix crontab basicsunix crontab basics
unix crontab basics
 
Sed Unix Utility Explained
Sed Unix Utility ExplainedSed Unix Utility Explained
Sed Unix Utility Explained
 
Shell script-sec
Shell script-secShell script-sec
Shell script-sec
 
Chap06
Chap06Chap06
Chap06
 

Semelhante a UNIX - Class6 - sed - Detail

Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlsana mateen
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionssana mateen
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing toolsroot_fibo
 
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docxIntroduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docxmariuse18nolet
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaewout2
 
University of North Texas 2 The sed Stream Editor .docx
University of North Texas 2 The sed Stream Editor .docxUniversity of North Texas 2 The sed Stream Editor .docx
University of North Texas 2 The sed Stream Editor .docxouldparis
 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminZoumanaDiomande1
 
Matlab: Procedures And Functions
Matlab: Procedures And FunctionsMatlab: Procedures And Functions
Matlab: Procedures And Functionsmatlab Content
 
Procedures And Functions in Matlab
Procedures And Functions in MatlabProcedures And Functions in Matlab
Procedures And Functions in MatlabDataminingTools Inc
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfpaijitk
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell ScriptDr.Ravi
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1Dr.Ravi
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressionsKrishna Nanda
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptxHandling Files Under Unix.pptx
Handling Files Under Unix.pptxHarsha Patel
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptxHandling Files Under Unix.pptx
Handling Files Under Unix.pptxHarsha Patel
 

Semelhante a UNIX - Class6 - sed - Detail (20)

Strings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perlStrings,patterns and regular expressions in perl
Strings,patterns and regular expressions in perl
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressions
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Unit 8 text processing tools
Unit 8 text processing toolsUnit 8 text processing tools
Unit 8 text processing tools
 
Unix Tutorial
Unix TutorialUnix Tutorial
Unix Tutorial
 
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docxIntroduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 BTo.docx
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
University of North Texas 2 The sed Stream Editor .docx
University of North Texas 2 The sed Stream Editor .docxUniversity of North Texas 2 The sed Stream Editor .docx
University of North Texas 2 The sed Stream Editor .docx
 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux admin
 
Matlab: Procedures And Functions
Matlab: Procedures And FunctionsMatlab: Procedures And Functions
Matlab: Procedures And Functions
 
Procedures And Functions in Matlab
Procedures And Functions in MatlabProcedures And Functions in Matlab
Procedures And Functions in Matlab
 
stringsinpython-181122100212.pdf
stringsinpython-181122100212.pdfstringsinpython-181122100212.pdf
stringsinpython-181122100212.pdf
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Unix - Filters
Unix - FiltersUnix - Filters
Unix - Filters
 
Talk Unix Shell Script
Talk Unix Shell ScriptTalk Unix Shell Script
Talk Unix Shell Script
 
Talk Unix Shell Script 1
Talk Unix Shell Script 1Talk Unix Shell Script 1
Talk Unix Shell Script 1
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptxHandling Files Under Unix.pptx
Handling Files Under Unix.pptx
 
Handling Files Under Unix.pptx
Handling Files Under Unix.pptxHandling Files Under Unix.pptx
Handling Files Under Unix.pptx
 
TheUnixPipeandFilters
TheUnixPipeandFiltersTheUnixPipeandFilters
TheUnixPipeandFilters
 

Mais de Nihar Ranjan Paital

Mais de Nihar Ranjan Paital (11)

Oracle Select Query
Oracle Select QueryOracle Select Query
Oracle Select Query
 
Useful macros and functions for excel
Useful macros and functions for excelUseful macros and functions for excel
Useful macros and functions for excel
 
Unix - Class7 - awk
Unix - Class7 - awkUnix - Class7 - awk
Unix - Class7 - awk
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
 
UNIX - Class2 - vi Editor
UNIX - Class2 - vi EditorUNIX - Class2 - vi Editor
UNIX - Class2 - vi Editor
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
 
UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1UNIX - Class4 - Advance Shell Scripting-P1
UNIX - Class4 - Advance Shell Scripting-P1
 
Test funda
Test fundaTest funda
Test funda
 
Csql for telecom
Csql for telecomCsql for telecom
Csql for telecom
 
Select Operations in CSQL
Select Operations in CSQLSelect Operations in CSQL
Select Operations in CSQL
 

Último

Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

UNIX - Class6 - sed - Detail

  • 1. UNIX - sed Non-Interactive Stream Editor Presentation By Nihar R Paital
  • 2. Introduction  Developer : Lee E. McMahon  Developed during: 1973-1974  Developed at : Bell Labs  Category : UNIX Utility  Supported by : All UNIX flavors Nihar R Paital
  • 3. For practicing the commands please create a file test1.txt and copy the below contents into test1.txt s s sprint Telecom 3sprint Telecom sprint we are working in sprint IBM 0IBM nihar,rahulk,sam,papau We are working in IBM 6We are working in IBM nihar:rahulk:sam:papau nihar,rahulk,sam We are working in IBM India Nihar R Paital
  • 4. It performs basic text transformation on an input stream ( A file / input from a pipeline )  Transformation using input file $ sed -e ‘s/oldval/newval/g’ inputFile > outputFile Example: $ sed -e ‘s/mumbai/pune/g’ stud.txt > stud.txt.bak  Transformation using a filter in a pipeline $ generate_data | sed -e ‘s/oldval/newval/g’ Example: $ cat stud.txt | sed -e ‘s/mumbai/pune/g’ > stud.txt.bak Nihar R Paital
  • 5. Main options of sed  p - print  d - delete  s - substitute Nihar R Paital
  • 6. Below special characters have vital role using sed Character Description  ^ Matches the beginning of the line.  $ Matches the end of the line.  . Matches any single character.  * Will match zero or more occurrences of the previous character.  [] Matches all the characters inside the [ ]. Nihar R Paital
  • 7. Examples (^ Matches the beginning of the line) $ sed '/^sprint/p' test1.txt Will Print the lines 2 times which contain sprint as a first ward of the line $ sed -n '/^sprint/p' test1.txt Will Print the lines which contain sprint as a first ward of the line $ sed 's/^sprint/IBM INDIA/g' test1.txt Will Substitute “IBM INDIA” in place of “sprint” if it appears at beginning of line. $ sed '/^sprint/d' test1.txt Will delete all lines containing “sprint” as a first word R Paital line. Nihar of the
  • 8. Example ($ Matches the end of the line) $ sed '/sprint$/p' test1.txt Will Print the lines 2 times which contain sprint as a last ward of the line $ sed -n '/sprint$/p' test1.txt Will Print the lines which contain sprint as a first ward of the line $ sed 's/sprint$/IBM INDIA/g' test1.txt Will Substitute “IBM INDIA” in place of “sprint” if it appears at end of line. $ sed '/sprint$/d' test1.txt Will delete all lines containing “sprint” as a first word of the line. $ sed -n '/^$/p' test1.txt Will delete all blank lines Nihar R Paital
  • 9. Example (. Matches any single character) $ sed -n '/./p' test1.txt It will print the lines which at least contains a single Character. It can be used for ignoring all blank lines. $ sed -n '/../p' test1.txt It will print the lines which at least contains a single Character. $ sed -n '/IB./p' test1.txt It will print the lines which at least contains a single Character after the String IB”. Nihar R Paital
  • 10. Example (* Will match zero or more occurrences of the previous character) $ sed -n '/ */p' test1.txt It will print all lines like “cat test1.txt” $ sed -n '/ */p' test1.txt It will print the lines which contains at leaset 2 characters except delimited lines. $ sed -n '/.*,.*,.*/p' test1.txt It will print the lines where the strings are separated by at least 3 commas(,). $ sed -n '/.*,.*,.*/p' test1.txt | cut -d"," -f 3 It will print the 3rd filed of the lines where the strings are separated by at least 3 commas(,). $ sed -n '/We*/p' test1.txt Nihar R Paital It will print all the lines where at least the string “We” is present
  • 11. Example ([ ] Matches all the characters inside the [ ]) $ sed -n '/[abc]/p' test1.txt This will print all the lines which contains either a or b or c as part of the line. $ sed -n '/^[0-9]/p' test1.txt This will print all the lines which contains the digit 0 to 9 as part of line $ sed -n '/^[^0-9]/p' test1.tx This will print all the lines which does not contains the digit 0 to 9 as part of line $ sed 's/[abc]/we/g' test1.txt This will replace the string “WE” where either a or b or c is present as part of the line. Nihar R Paital
  • 12. Sed – Line number manipulation 1 first line $ last line m,n m to n line Example: $ sed -n '3,7p' test1.txt It will print the lines from 3 to 7 $ sed -n 'n;n;n;p' test1.txt ( every 4th line ) It will print every 4th line of the file Nihar R Paital