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
Total Pageviews
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.
Ruby - Overview
Ruby is a pure object-oriented programming language. It was created in 1993 by Yukihiro Matsumoto of Japan.
You can find the name Yukihiro Matsumoto on the Ruby mailing list at www.ruby-lang.org. Matsumoto is also known as Matz in the Ruby community.
You can find the name Yukihiro Matsumoto on the Ruby mailing list at www.ruby-lang.org. Matsumoto is also known as Matz in the Ruby community.
Ruby - Environment Setup
Try it Option Online
You really do not need to set up your own environment to start learning Ruby programming language. Reason is very simple, we already have set up Ruby Programming environment online, so that you can execute almost all the tutorial examples online at the same time when you are doing your theory work.
Ruby - Syntax
Let us write a simple program in ruby. All ruby files will have extension .rb. So, put the following source code in a test.rb file.
#!/usr/bin/ruby -w puts "Hello, Ruby!";Here, I assumed that you have Ruby interpreter available in /usr/bin directory. Now, try to run this program as follows:
Ruby - Classes and Objects
Ruby is a perfect Object Oriented Programming Language. The features of the object-oriented programming language include:
- Data Encapsulation:
- Data Abstraction:
- Polymorphism:
- Inheritance:
Ruby Variables, Constants and Literals
Variables are the memory locations which hold any data to be used by any program.
There are five types of variables supported by Ruby. You already have gone through a small description of these variables in previous chapter as well. These five types of variables are explained in this chapter.
There are five types of variables supported by Ruby. You already have gone through a small description of these variables in previous chapter as well. These five types of variables are explained in this chapter.
Ruby Operators
Ruby supports a rich set of operators, as you'd expect from a modern
language. Most operators are actually method calls. For example, a + b
is interpreted as a.+(b), where the + method in the object referred to
by variable a is called with b as its argument.
For each operator (+ - * / % ** & | ^ << >> && ||), there is a corresponding form of abbreviated assignment operator (+= -= etc.)
For each operator (+ - * / % ** & | ^ << >> && ||), there is a corresponding form of abbreviated assignment operator (+= -= etc.)
Ruby Comments
Comments are lines of annotation within Ruby code that are ignored at
runtime. A single line comment starts with # character and they extend
from # to the end of the line as follows:
#!/usr/bin/ruby -w # This is a single line comment.
Ruby if...else, case, unless
Ruby offers conditional structures that are pretty common to modern
languages. Here, we will explain all the conditional statements and
modifiers available in Ruby.
Ruby if...else Statement:
Syntax:
if conditional [then] code... [elsif conditional [then] code...]... [else code...]
Ruby Loops - while, for, until, break, redo and retry
Loops in Ruby are used to execute the same block of code a specified
number of times. This chapter details all the loop statements supported
by Ruby.
Ruby Methods
Ruby methods are very similar to functions in any other programming
language. Ruby methods are used to bundle one or more repeatable
statements into a single unit.
Method names should begin with a lowercase letter. If you begin a method name with an uppercase letter, Ruby might think that it is a constant and hence can parse the call incorrectly.
Method names should begin with a lowercase letter. If you begin a method name with an uppercase letter, Ruby might think that it is a constant and hence can parse the call incorrectly.
Ruby Blocks
You have seen how Ruby defines methods where you can put number of
statements and then you call that method. Similarly, Ruby has a concept
of Block.
- A block consists of chunks of code.
- You assign a name to a block.
- The code in the block is always enclosed within braces ({}).
Ruby Modules and Mixins
Modules are a way of grouping together methods, classes, and constants. Modules give you two major benefits.
- Modules provide a namespace and prevent name clashes.
- Modules implement the mixin facility.
Ruby Strings
A String object in Ruby holds and manipulates an arbitrary sequence of one or more bytes, typically representing characters
that represent human language.
The simplest string literals are enclosed in single quotes (the apostrophe character). The text within the quote marks is the value of the string:
The simplest string literals are enclosed in single quotes (the apostrophe character). The text within the quote marks is the value of the string:
Ruby Arrays
Ruby arrays are ordered, integer-indexed collections of any object.
Each element in an array is associated with and referred to by an index.
Array indexing starts at 0, as in C or Java. A negative index is assumed relative to the end of the array --- that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on.
Array indexing starts at 0, as in C or Java. A negative index is assumed relative to the end of the array --- that is, an index of -1 indicates the last element of the array, -2 is the next to last element in the array, and so on.
Ruby Hashes
A Hash is a collection of key-value pairs like this: "employee" =>
"salary". It is similar to an Array, except that indexing is done via
arbitrary keys of any object type, not an integer index.
The order in which you traverse a hash by either key or value may seem arbitrary and will generally not be in the insertion order. If you attempt to access a hash with a key that does not exist, the method will return nil.
The order in which you traverse a hash by either key or value may seem arbitrary and will generally not be in the insertion order. If you attempt to access a hash with a key that does not exist, the method will return nil.
Date & Time in Ruby
The Time class represents dates and times in Ruby. It is a
thin layer over the system date and time functionality provided by the
operating system. This class may be unable on your system to represent
dates before 1970 or after 2038.
This tutorial will make you familiar with all the most wanted concepts of date and time.
This tutorial will make you familiar with all the most wanted concepts of date and time.
Ruby Ranges
Ranges occur everywhere: January to December, 0 to 9, lines 50
through 67, and so on. Ruby supports ranges and allows us to use ranges
in a variety of ways:
- Ranges as Sequences
- Ranges as Conditions
- Ranges as Intervals
Ruby Iterators - each and collect
Iterators are nothing but methods supported by collections. Objects that store a group of data members are called collections. In Ruby, arrays and hashes can be termed collections.
Iterators return all the elements of a collection, one after the other. We will be discussing two iterators here, each and collect. Let's look at these in detail.
Iterators return all the elements of a collection, one after the other. We will be discussing two iterators here, each and collect. Let's look at these in detail.
Ruby File I/O, Directories
Ruby provides a whole set of I/O-related methods implemented in the
Kernel module. All the I/O methods are derived from the class IO.
The class IO provides all the basic methods, such as read, write, gets, puts, readline, getc, and printf.
This chapter will cover all the basic I/O functions available in Ruby. For more functions, please refer to Ruby Class IO.
The class IO provides all the basic methods, such as read, write, gets, puts, readline, getc, and printf.
This chapter will cover all the basic I/O functions available in Ruby. For more functions, please refer to Ruby Class IO.
Ruby Exceptions
The execution and the exception always go together. If you are
opening a file, which does not exist, then if you did not handle this
situation properly, then your program is considered to be of bad
quality.
The program stops if an exception occurs. So exceptions are used to handle various type of errors, which may occur during a program execution and take appropriate action instead of halting program completely.
The program stops if an exception occurs. So exceptions are used to handle various type of errors, which may occur during a program execution and take appropriate action instead of halting program completely.
Object Oriented Ruby
Ruby is pure object-oriented language and everything appears to Ruby
as an object. Every value in Ruby is an object, even the most primitive
things: strings, numbers and even true and false. Even a class itself is
an object that is an instance of the Class class. This chapter will take you through all the major functionalities related to Object Oriented Ruby.
Ruby Regular Expressions
A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings using
a specialized syntax held in a pattern.
A regular expression literal is a pattern between slashes or between arbitrary delimiters followed by %r as follows:
A regular expression literal is a pattern between slashes or between arbitrary delimiters followed by %r as follows:
Ruby/DBI Tutorial
This session will teach you how to access a database using Ruby. The Ruby DBI module provides a database-independent interface for Ruby scripts similar to that of the Perl DBI module.
DBI stands for Database independent interface for Ruby which means DBI provides an abstraction layer between the Ruby code and the underlying database, allowing you to switch database implementations really easily.
DBI stands for Database independent interface for Ruby which means DBI provides an abstraction layer between the Ruby code and the underlying database, allowing you to switch database implementations really easily.
Ruby Web Applications - CGI Programming
Ruby is a general-purpose language; it can't properly be called a web language at all. Even so, web applications and web tools in general are among the most common uses of Ruby.
Not only can you write your own SMTP server, FTP daemon, or Web server in Ruby, but you can also use Ruby for more usual tasks such as CGI programming or as a replacement for PHP.
Please spend few minutes with CGI Programming Tutorial for more detail on CGI Programming.
Not only can you write your own SMTP server, FTP daemon, or Web server in Ruby, but you can also use Ruby for more usual tasks such as CGI programming or as a replacement for PHP.
Please spend few minutes with CGI Programming Tutorial for more detail on CGI Programming.
Sending Email using Ruby - SMTP
Simple Mail Transfer Protocol (SMTP) is a protocol, which handles sending e-mail and routing e-mail between mail servers.
Ruby provides Net::SMTP class for Simple Mail Transfer Protocol (SMTP) client-side connection and provides two class methods new and start.
Ruby provides Net::SMTP class for Simple Mail Transfer Protocol (SMTP) client-side connection and provides two class methods new and start.
Ruby Socket Programming
Ruby provides two levels of access to network services. At a low level, you can access the basic socket support in the underlying operating system, which allows you to implement clients and servers for both connection-oriented and connectionless protocols.
Ruby/XML, XSLT and XPath Tutorial
What is XML ?
The Extensible Markup Language (XML) is a markup language much like HTML or SGML. This is recommended by the World Wide Web Consortium and available as an open standard.XML is a portable, open source language that allows programmers to develop applications that can be read by other applications, regardless of operating system and/or developmental language.
XML is extremely useful for keeping track of small to medium amounts of data without requiring a SQL-based backbone.
Web Services with Ruby - SOAP4R
What is SOAP ?
The Simple Object Access Protocol (SOAP) is a cross-platform and language-independent RPC protocol based on XML and, usually (but not necessarily) HTTP.It uses XML to encode the information that makes the remote procedure call, and HTTP to transport that information across a network from clients to servers and vice versa.
Ruby/Tk Guide
Introduction:
The standard graphical user interface (GUI) for Ruby is Tk. Tk started out as the GUI for the Tcl scripting language developed by John Ousterhout.Tk has the unique distinction of being the only cross-platform GUI. Tk runs on Windows, Mac, and Linux and provides a native look-and-feel on each operating system.
Ruby/LDAP Tutorial
Ruby/LDAP is an extension library for Ruby. It provides the interface to some LDAP libraries like OpenLDAP, UMich LDAP, Netscape SDK, ActiveDirectory.
The common API for application development is described in RFC1823 and is supported by Ruby/LDAP.
The common API for application development is described in RFC1823 and is supported by Ruby/LDAP.
Ruby - Multithreading
Traditional programs have a single thread of execution: the statements or instructions that comprise the program are executed sequentially until the program terminates.
A multithreaded program has more than one thread of execution. Within each thread, statements are executed sequentially, but the threads themselves may be executed in parallel on a multicore CPU, for example. Often on a single CPU machine, multiple threads are not actually executed in parallel, but parallelism is simulated by interleaving the execution of the threads.
A multithreaded program has more than one thread of execution. Within each thread, statements are executed sequentially, but the threads themselves may be executed in parallel on a multicore CPU, for example. Often on a single CPU machine, multiple threads are not actually executed in parallel, but parallelism is simulated by interleaving the execution of the threads.
Subscribe to:
Posts (Atom)