The acronym SED stands for Stream EDitor. It is a simple yet
powerful utility that parses the text and transforms it seamlessly. SED
was developed during 1973–74 by Lee E. McMahon of Bell Labs. Today, it
runs on all major operating systems.
পৃষ্ঠাসমূহ
Labels
Search Your Article
CS
Pageviews
Showing posts with label Sed Tutorial. Show all posts
Showing posts with label Sed Tutorial. Show all posts
Monday, April 3, 2017
Stream Editor - Environment
This chapter describes how to set up the SED environment on your GNU/Linux system.
Installation Using Package Manager
Generally, SED is available by default on most GNU/Linux distributions. Use which command to identify whether it is present on your system or not. If not, then install SED on Debian based GNU/Linux using apt package manager as follows:Stream Editor - Workflow
In this chapter, we will explore how SED exactly works. To become an
expert SED user, one needs to know its internals. SED follows a simple
workflow: Read, Execute, and Display. The following diagram depicts the
workflow.
Stream Editor - Basic Syntax
This chapter introduces the basic commands that SED supports and
their command-line syntax. SED can be invoked in the following two
forms:
sed [-n] [-e] 'command(s)' files sed [-n] -f scriptfile files
Stream Editor - Loops
Like other programming languages, SED too provides a looping and
branching facility to control the flow of execution. In this chapter, we
are going to explore more about how to use loops and branches in SED.
A loop in SED works similar to a goto statement. SED can jump to the line marked by the label and continue executing the remaining commands. In SED, we can define a label as follows:
A loop in SED works similar to a goto statement. SED can jump to the line marked by the label and continue executing the remaining commands. In SED, we can define a label as follows:
Stream Editor - Branches
Branches can be created using the t command. The t command
jumps to the label only if the previous substitute command was
successful. Let us take the same example as in the previous chapter, but
instead of printing a single hyphen(-), now we print four hyphens. The
following example illustrates the usage of the t command.
Stream Editor - Pattern Buffer
One of the basic operations we perform on any file is display its contents. For this purpose, we can use the print command which prints the contents of the pattern buffer. So let us learn more about the pattern buffer
First create a file containing the line number, the name of the book, its author, and the number of pages. In this tutorial, we will be using this file. You can use any text file according to your convenience. Our text file will look like this:
First create a file containing the line number, the name of the book, its author, and the number of pages. In this tutorial, we will be using this file. You can use any text file according to your convenience. Our text file will look like this:
Stream Editor - Pattern Range
In the previous chapter, we learnt how SED handles an address range.
This chapter covers how SED takes care of a pattern range. A pattern
range can be a simple text or a complex regular expression. Let us take
an example. The following example prints all the books of the author
Paulo Coelho.
[jerry]$ sed -n '/Paulo/ p' books.txt
Stream Editor - Basic Commands
This chapter describes several useful SED commands.
Delete Command
SED provides various commands to manipulate text. Let us first explore about the delete command. Here is how you execute a delete command:[address1[,address2]]daddress1 and address2 are the starting and the ending addresses respectively, which can be either line numbers or pattern strings. Both of these addresses are optional parameters.
Stream Editor - Special Characters
SED provides two special characters which are treated as commands.
This chapter illustrates the usage of these two special characters.
= Command
The "=" command deals with line numbers. Given below is the syntax of the "=" command:[/pattern/]= [address1[,address2]]=
Stream Editor - Strings
Substitute Command
Text substitution operations like "find and replace" are common in any text editor. In this section, we illustrate how SED performs text substitution. Given below is the syntax of the substitution command.[address1[,address2]]s/pattern/replacement/[flags]
Stream Editor - Managing Patterns
We have already discussed the use of pattern and hold buffer. In this
chapter, we are going to explore more about their usage. Let us discuss
the n command which prints the pattern space. It will be used in conjunction with other commands. Given below is the syntax of then command.
[address1[,address2]]nLet us take an example.
Stream Editor - Regular Expressions
It is the regular expressions that make SED powerful and efficient. A
number of complex tasks can be solved with regular expressions. Any
command-line expert knows the power of regular expressions.
Like many other GNU/Linux utilities, SED too supports regular expressions, which are often referred to as as regex. This chapter describes regular expressions in detail. The chapter is divided into three sections: Standard regular expressions, POSIX classes of regular expressions, and Meta characters.
Like many other GNU/Linux utilities, SED too supports regular expressions, which are often referred to as as regex. This chapter describes regular expressions in detail. The chapter is divided into three sections: Standard regular expressions, POSIX classes of regular expressions, and Meta characters.
Stream Editor - Useful Recipes
SED is an amazing utility that allows multiple ways to solve a
problem. This is the UNIX way and SED perfectly proves that. GNU/Linux
provides many useful utilities to perform day-to-day tasks. Let us
simulate a few utilities using SED. Sometimes it may appear we are
solving an easy problem the hard way, but the purpose is just to
demonstrate the power of SED.
Stream Editor - Quick Guide
Stream Editor - Overview
The acronym SED stands for Stream EDitor. It is a simple yet powerful utility that parses the text and transforms it seamlessly. SED was developed during 1973–74 by Lee E. McMahon of Bell Labs. Today, it runs on all major operating systems.Sed - Useful Resources
The following resources contain additional information on SED. Please use them to get more in-depth knowledge on this topic.
Discuss Sed
This tutorial takes you through all about Stream EDitor (Sed), one of
the most prominent text-processing utilities on GNU/Linux. Similar to
many other GNU/Linux utilities, it is stream-oriented and uses simple
programming language. It is capable of solving complex text processing
tasks with few lines of code. This easy, yet powerful utility makes
GNU/Linux more interesting.
Subscribe to:
Posts (Atom)