Sed – Useful Resources ”; Previous Next The following resources contain additional information on SED. Please use them to get more in-depth knowledge on this topic. Useful Links on SED GNU Sed – Stream Editor Manual by GNU Wikipedia – Wikipedia reference for Sed Useful Books on SED To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
Category: Computer Programming
Sed – Basic Syntax
Stream Editor – Basic Syntax ”; Previous Next 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 The first form allows to specify the commands in-line and they are enclosed within single quotes. The later allows to specify a script file that contains SED commands. However, we can use both forms together multiple times. SED provides various command-line options to control its behavior. Let us see how we can specify multiple SED commands. SED provides the delete command to delete certain lines. Let us delete the 1st, 2nd, and 5th lines. For the time being, ignore all the details of the delete command. We will discuss more about the delete command later. First, display the file contents using the cat command. [jerry]$ cat books.txt On executing the above code, you get the following result: 1) A Storm of Swords, George R. R. Martin, 1216 2) The Two Towers, J. R. R. Tolkien, 352 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 Now instruct SED to remove only certain lines. Here, to delete three lines, we have specified three separate commands with -e option. [jerry]$ sed -e ”1d” -e ”2d” -e ”5d” books.txt On executing the above code, you get the following result: 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 6) A Game of Thrones, George R. R. Martin, 864 Additionally, we can write multiple SED commands in a text file and provide the text file as an argument to SED. SED can apply each command on the pattern buffer. The following example illustrates the second form of SED. First, create a text file containing SED commands. For easy understanding, let us use the same SED commands. [jerry]$ echo -e “1dn2dn5d” > commands.txt [jerry]$ cat commands.txt On executing the above code, you get the following result: 1d 2d 5d Now instruct the SED to read commands from the text file. Here, we achieve the same result as shown in the above example. [jerry]$ sed -f commands.txt books.txt On executing the above code, you get the following result: 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 6) A Game of Thrones,George R. R. Martin, 864 Standard Options SED supports the following standard options: -n: Default printing of pattern buffer. For example, the following SED command does not show any output: [jerry]$ sed -n ”” quote.txt -e : Next argument is an editing command. Here, angular brackets imply mandatory parameter. By using this option, we can specify multiple commands. Let us print each line twice: [jerry]$ sed -e ”” -e ”p” quote.txt On executing the above code, you get the following result: There is only one thing that makes a dream impossible to achieve: the fear of failure. There is only one thing that makes a dream impossible to achieve: the fear of failure. – Paulo Coelho, The Alchemist – Paulo Coelho, The Alchemist -f : Next argument is a file containing editing commands. The angular brackets imply mandatory parameter. In the following example, we specify print command through file: [jerry]$ echo “p” > commands [jerry]$ sed -n -f commands quote.txt On executing the above code, you get the following result: There is only one thing that makes a dream impossible to achieve: the fear of failure. – Paulo Coelho, The Alchemist GNU Specific Options Let us quickly go through the GNU specific SED options. Note that these options are GNU specific; and may not be supported by other variants of the SED. In later sections, we will discuss these options in more details. -n, –quiet, –silent: Same as standard -n option. -e script, –expression=script: Same as standard -e option. -f script-file, –file=script-file: Same as standard -f option. –follow-symlinks: If this option is provided, the SED follows symbolic links while editing files in place. -i[SUFFIX], –in-place[=SUFFIX]: This option is used to edit file in place. If suffix is provided, it takes a backup of the original file, otherwise it overwrites the original file. -l N, –line-lenght=N: This option sets the line length for l command to N characters. –posix: This option disables all GNU extensions. -r, –regexp-extended: This option allows to use extended regular expressions rather than basic regular expressions. -u, –unbuffered: When this option is provided, the SED loads minimal amount of data from the input files and flushes the output buffers more often. It is useful for editing the output of “tail -f” when you do not want to wait for the output. -z, –null-data: By default, the SED separates each line by a new-line character. If NULL-data option is provided, it separates the lines by NULL characters. Print Page Previous Next Advertisements ”;
Scala Collections – HashMap
Scala Collections – HashMap ”; Previous Next Scala map is a collection of key/value pairs. Any value can be retrieved based on its key. Keys are unique in the Map, but values need not be unique. HashMap implements immutable map and uses hash table to implement the same. Declaring HashMap Variables The following is the syntax for declaring an HashMap variable. Syntax val colors = HashMap(“red” -> “#FF0000”, “azure” -> “#F0FFFF”, “peru” -> “#CD853F”) Here, colors is declared as an hash-map of Strings, Int which has three key-value pairs. Values can be added by using commands like the following − Command var myMap1: HashMap[Char, Int] = colors + (“black” -> “#000000”); Processing HashMap Below is an example program of showing how to create, initialize and process HashMap − Example import scala.collection.immutable.HashMap object Demo { def main(args: Array[String]) = { var myMap: HashMap[String,String] = HashMap( “red” -> “#FF0000”, “azure” -> “#F0FFFF”, “peru” -> “#CD853F” ); // Add an element var myMap1: HashMap[String,String] = myMap + (“white” -> “#FFFFFF”); // Print key values myMap.keys.foreach{ i => print( “Key = ” + i ) println(” Value = ” + myMap(i) ) } if( myMap.contains( “red” )) { println(“Red key exists with value :” + myMap(“red”)) } else { println(“Red key does not exist”) } if( myMap.contains( “maroon” )) { println(“Maroon key exists with value :” + myMap(“maroon”)) } else { println(“Maroon key does not exist”) } //removing element var myMap2: HashMap[String,String] = myMap – (“white”); // Create empty map var myMap3: HashMap[String,String] = HashMap.empty[String, String]; println(myMap1); println(myMap2); println(myMap3); } } Save the above program in Demo.scala. The following commands are used to compile and execute this program. Command >scalac Demo.scala >scala Demo Output Key = azure Value = #F0FFFF Key = peru Value = #CD853F Key = red Value = #FF0000 Red key exists with value :#FF0000 Maroon key does not exist HashMap(azure -> #F0FFFF, peru -> #CD853F, white -> #FFFFFF, red -> #FF0000) HashMap(azure -> #F0FFFF, peru -> #CD853F, red -> #FF0000) HashMap() Print Page Previous Next Advertisements ”;
Sed – Basic Commands
Stream Editor – Basic Commands ”; Previous Next 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]]d address1 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. As the name suggests, the delete command is used to perform delete operation and since the SED operates on line, we can say that this command is used to delete lines. Note that the delete command removes lines only from the pattern buffer; the line is not sent to the output stream and the original file remains unchanged. The following example illustrates the point. [jerry]$ sed ”d” books.txt But where is the output? If no line address is provided, then the SED operates on every line by default. Hence, it deletes all the lines from the pattern buffer. That is why the command does not print anything on the standard output. Let us instruct the SED to operate only on certain lines. The following example removes the 4th line only. [jerry]$ sed ”4d” books.txt On executing the above code, you get the following result: 1) A Storm of Swords, George R. R. Martin, 1216 2) The Two Towers, J. R. R. Tolkien, 352 3) The Alchemist, Paulo Coelho, 197 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 Additionally, SED also accepts address range using comma(,). We can instruct the SED to remove N1 to N2 lines. For instance, the following example deletes all the lines from 2 through 4. [jerry]$ sed ”2, 4 d” books.txt On executing the above code, you get the following result: 1) A Storm of Swords, George R. R. Martin, 1216 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 SED”s address range is not only limited to numbers. We can also specify patterns as an address. The following example removes all the books of the author Paulo Coelho. [jerry]$ sed ”/Paulo Coelho/d” books.txt On executing the above code, you get the following result: 1) A Storm of Swords, George R. R. Martin, 1216 2) The Two Towers, J. R. R. Tolkien, 352 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 6) A Game of Thrones, George R. R. Martin, 864 We can also specify an address range using textual pattern. The following example removes all lines between the patterns Storm and Fellowship. [jerry]$ sed ”/Storm/,/Fellowship/d” books.txt 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 In addition to this, we can also use dollar($), plus(+), and tilde(~) operators with SED. Write Command One of the important operations we perform on any file is backup, i.e., we make another copy of the file. SED provides the write command to store the contents of the pattern buffer in a file. Given below is the syntax of the write command which is similar to the delete command. [address1[,address2]]w file Here, address1 and address2 are the starting and the ending address respectively, which can be either line numbers or pattern strings. Both of these addresses are optional parameters. In the above syntax, w refers to the write command and file is the file name in which you store contents. Be careful with the file parameter. When a file name is provided, the SED creates a file on the fly if it is not present, and overwrites it if it is already present. Let us make an exact copy of the file using SED. Note that there must be exactly one space between w and file. [jerry]$ sed -n ”w books.bak” books.txt We created another file called books.bak. Now verify that both the files have identical content. [jerry]$ diff books.txt books.bak [jerry]$ echo $? On executing the above code, you get the following result: 0 You may assume that the cp command does exactly the same thing. Yes! The cp command does the same thing, but SED is a matured utility. It allows creating a file containing only certain lines from the source file. Let us store only even lines to another file. [jerry]$ sed -n ”2~2 w junk.txt” books.txt [jerry]$ cat junk.txt On executing the above code, you get the following result: 2) The Two Towers, J. R. R. Tolkien, 352 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 6) A Game of Thrones, George R. R. Martin, 864 You can also use comma(,), dollar($), and plus(+) operators with the write command. In addition to this, SED also supports pattern matching with the write command. Suppose you want to store all the books of individual authors into a separate file. One boring and lengthy way is do it manually, and the smarter way is to use SED. [jerry]$ sed -n -e ”/Martin/ w Martin.txt” -e ”/Paulo/ w Paulo.txt” -e ”/Tolkien/ w Tolkien.txt” books.txt In the above example, we are matching each line against a pattern and storing the matched line in a particular file. It is very simple. To specify multiple commands, we used -e switch of the SED command. Now let use see what each file contains: [jerry]$ cat Martin.txt On executing the above code, you get the following result: 1) A Storm of Swords, George R. R. Martin, 1216 6) A Game of Thrones, George R. R. Martin, 864 Let us display the file contents. [jerry]$ cat Paulo.txt On executing the above code, you get the following result: 3) The Alchemist, Paulo Coelho, 197 5) The Pilgrimage, Paulo Coelho, 288 Let us display the file contents. [jerry]$ cat Tolkien.txt On executing the above code, you get the following result: 2) The Two Towers, J. R. R. Tolkien, 352 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 Excellent! We got the expected result. SED is
Sed – Pattern Buffer
Stream Editor – Pattern Buffer ”; Previous Next 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: [jerry]$ vi books.txt 1) A Storm of Swords, George R. R. Martin, 1216 2) The Two Towers, J. R. R. Tolkien, 352 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 5) The Pilgrimage, Paulo Coelho,288 6) A Game of Thrones, George R. R. Martin, 864 Now, let us print the file contents. [jerry]$ sed ”p” books.txt When the above code is executed, it will produce the following result. 1) A Storm of Swords, George R. R. Martin, 1216 1) A Storm of Swords, George R. R. Martin, 1216 2) The Two Towers, J. R. R. Tolkien, 352 2) The Two Towers, J. R. R. Tolkien, 352 3) The Alchemist, Paulo Coelho, 197 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 5) The Pilgrimage, Paulo Coelho, 288 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 6) A Game of Thrones, George R. R. Martin, 864 You might wonder why each line is being displayed twice. Let us find out. Do you remember the workflow of SED? By default, SED prints the contents of the pattern buffer. In addition, we have included a print command explicitly in our command section. Hence each line is printed twice. But don”t worry. SED has the -n option to suppress the default printing of the pattern buffer. The following command illustrates that. [jerry]$ sed -n ”p” books.txt When the above code is executed, it will produce the following result. 1) A Storm of Swords, George R. R. Martin, 1216 2) The Two Towers, J. R. R. Tolkien, 352 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 Congratulations! we got the expected result. By default, SED operates on all lines. But we can force SED to operate only on certain lines. For instance, in the example below, SED only operates on the 3rd line. In this example, we have specified an address range before the SED command. [jerry]$ sed -n ”3p” books.txt When the above code is executed, it will produce the following result. 3) The Alchemist, Paulo Coelho, 197 Additionally, we can also instruct SED to print only certain lines. For instance, the following code prints all the lines from 2 to 5. Here we have used the comma(,) operator to specify the address range. [jerry]$ sed -n ”2,5 p” books.txt When the above code is executed, it will produce the following result. 2) The Two Towers, J. R. R. Tolkien, 352 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 5) The Pilgrimage, Paulo Coelho, 288 There is also a special character Dollar($) which represents the last line of the file. So let us print the last line of the file. [jerry]$ sed -n ”$ p” books.txt When the above code is executed, it will produce the following result. 6) A Game of Thrones, George R. R. Martin, 864 However we can also use Dollar($) character to specify address range. Below example prints through line 3 to last line. [jerry]$ sed -n ”3,$ p” books.txt When the above code is executed, it will produce the following result. 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 We learnt how to specify an address range using the comma(,) operator. SED supports two more operators that can be used to specify address range. First is the plus(+) operator and it can be used with the comma(,) operator. For instance M, +n will print the next n lines starting from line number M. Sounds confusing? Let us check it with a simple example. The following example prints the next 4 lines starting from line number 2. [jerry]$ sed -n ”2,+4 p” books.txt When the above code is executed, it will produce the following result. 2) The Two Towers, J. R. R. Tolkien, 352 3) The Alchemist, Paulo Coelho, 197 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 5) The Pilgrimage, Paulo Coelho, 288 6) A Game of Thrones, George R. R. Martin, 864 Optionally, we can also specify address range using the tilde(~) operator. It uses M~n form. It indicates that SED should start at line number M and process every n(th) line. For instance, 50~5 matches line number 50, 55, 60, 65, and so on. Let us print only odd lines from the file. [jerry]$ sed -n ”1~2 p” books.txt When the above code is executed, it will produce the following result. 1) A Storm of Swords, George R. R. Martin, 1216 3) The Alchemist, Paulo Coelho, 197 5) The Pilgrimage, Paulo Coelho, 288 The following code prints only even lines from the file. [jerry]$ sed -n ”2~2 p” books.txt When the above code is executed, it will produce the following result. 2) The Two Towers, J. R. R. Tolkien, 352 4) The Fellowship of the Ring, J. R. R. Tolkien, 432 6) A Game of Thrones, George R. R. Martin, 864 Print Page
Discuss Scala Collections ”; Previous Next Scala has a rich set of collection library. Collections are containers of things. Those containers can be sequenced, linear sets of items like List, Tuple, Option, Map, etc. The collections may have an arbitrary number of elements or be bounded to zero or one element (e.g., Option). Print Page Previous Next Advertisements ”;
Scala Collections – TreeSet
Scala Collections – TreeSet ”; Previous Next Scala Set is a collection of pairwise different elements of the same type. In other words, a Set is a collection that contains no duplicate elements. TreeSet implements immutable sets and keeps elements in sorted order. Declaring TreeSet Variables The following is the syntax for declaring an TreeSet variable. Syntax var z : TreeSet[String] = TreeSet(“Zara”,”Nuha”,”Ayan”) Here, z is declared as an tree-set of Strings which has three members. Values can be added by using commands like the following − Command var myList1: TreeSet[String] = myList + “Naira”; Processing TreeSet Below is an example program of showing how to create, initialize and process TreeSet − Example import scala.collection.immutable.TreeSet object Demo { def main(args: Array[String]) = { var mySet: TreeSet[String] = TreeSet(“Zara”,”Nuha”,”Ayan”); // Add an element var mySet1: TreeSet[String] = mySet + “Naira”; // Remove an element var mySet2: TreeSet[String] = mySet – “Nuha”; // Create empty set var mySet3: TreeSet[String] = TreeSet.empty[String]; println(mySet); println(mySet1); println(mySet2); println(mySet3); } } Save the above program in Demo.scala. The following commands are used to compile and execute this program. Command >scalac Demo.scala >scala Demo Output TreeSet(Ayan, Nuha, Zara) TreeSet(Ayan, Naira, Nuha, Zara) TreeSet(Ayan, Zara) TreeSet() Print Page Previous Next Advertisements ”;
Sed – Home
Sed Tutorial PDF Version Quick Guide Resources Job Search Discussion 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. Audience If you are a software developer, system administrator, or a GNU/Linux loving person, then this tutorial is for you. Prerequisites You must have basic understanding of GNU/Linux operating system and shell scripting. Print Page Previous Next Advertisements ”;
Sed – Regular Expressions
Stream Editor – Regular Expressions ”; Previous Next 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. Standard Regular Expressions Start of line (^) In regular expressions terminology, the caret(^) symbol matches the start of a line. The following example prints all the lines that start with the pattern “The”. [jerry]$ sed -n ”/^The/ p” books.txt On executing the above code, you get the following result: The Two Towers, J. R. R. Tolkien The Alchemist, Paulo Coelho The Fellowship of the Ring, J. R. R. Tolkien The Pilgrimage, Paulo Coelho End of Line ($) End of line is represented by the dollar($) symbol. The following example prints the lines that end with “Coelho”. [jerry]$ sed -n ”/Coelho$/ p” books.txt On executing the above code, you get the following result: The Alchemist, Paulo Coelho The Pilgrimage, Paulo Coelho Single Character (.) The Dot(.) matches any single character except the end of line character. The following example prints all three letter words that end with the character “t”. [jerry]$ echo -e “catnbatnratnmatnbattingnratsnmats” | sed -n ”/^..t$/p” On executing the above code, you get the following result: cat bat rat mat Match Character Set ([]) In regular expression terminology, a character set is represented by square brackets ([]). It is used to match only one out of several characters. The following example matches the patterns “Call” and “Tall” but not “Ball”. [jerry]$ echo -e “CallnTallnBall” | sed -n ”/[CT]all/ p” On executing the above code, you get the following result: Call Tall Exclusive Set ([^]) In exclusive set, the caret negates the set of characters in the square brackets. The following example prints only “Ball”. [jerry]$ echo -e “CallnTallnBall” | sed -n ”/[^CT]all/ p” On executing the above code, you get the following result: Ball Character Range ([-]) When a character range is provided, the regular expression matches any character within the range specified in square brackets. The following example matches “Call” and “Tall” but not “Ball”. [jerry]$ echo -e “CallnTallnBall” | sed -n ”/[C-Z]all/ p” On executing the above code, you get the following result: Call Tall Now let us modify the range to “A-P” and observe the result. [jerry]$ echo -e “CallnTallnBall” | sed -n ”/[A-P]all/ p” On executing the above code, you get the following result: Call Ball Zero on One Occurrence (?) In SED, the question mark (?) matches zero or one occurrence of the preceding character. The following example matches “Behaviour” as well as “Behavior”. Here, we made “u” as an optional character by using “?”. [jerry]$ echo -e “BehaviournBehavior” | sed -n ”/Behaviou?r/ p” On executing the above code, you get the following result: Behaviour Behavior One or More Occurrence (+) In SED, the plus symbol(+) matches one or more occurrences of the preceding character. The following example matches one or more occurrences of “2”. [jerry]$ echo -e “111n22n123n234n456n222″ | sed -n ”/2+/ p” On executing the above code, you get the following result: 22 123 234 222 Zero or More Occurrence (*) Asterisks (*) matches the zero or more occurrence of the preceding character. The following example matches “ca”, “cat”, “catt”, and so on. [jerry]$ echo -e “cancat” | sed -n ”/cat*/ p” On executing the above code, you get the following result: ca cat Exactly N Occurrences {n} {n} matches exactly “n” occurrences of the preceding character. The following example prints only three digit numbers. But before that, you need to create the following file which contains only numbers. [jerry]$ cat numbers.txt On executing the above code, you get the following result: 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 Let us write the SED expression. [jerry]$ sed -n ”/^[0-9]{3}$/ p” numbers.txt On executing the above code, you get the following result: 100 Note that the pair of curly braces is escaped by the “” character. At least n Occurrences {n,} {n,} matches at least “n” occurrences of the preceding character. The following example prints all the numbers greater than or equal to five digits. [jerry]$ sed -n ”/^[0-9]{5,}$/ p” numbers.txt On executing the above code, you get the following result: 10000 100000 1000000 10000000 100000000 1000000000 M to N Occurrence {m, n} {m, n} matches at least “m” and at most “n” occurrences of the preceding character. The following example prints all the numbers having at least five digits but not more than eight digits. [jerry]$ sed -n ”/^[0-9]{5,8}$/ p” numbers.txt On executing the above code, you get the following result: 10000 100000 1000000 10000000 Pipe (|) In SED, the pipe character behaves like logical OR operation. It matches items from either side of the pipe. The following example either matches “str1” or “str3”. [jerry]$ echo -e “str1nstr2nstr3nstr4″ | sed -n ”/str(1|3)/ p” On executing the above code, you get the following result: str1 str3 Note that the pair of the parenthesis and pipe (|) is escaped by the “” character. Escaping Characters There are certain special characters. For example, newline is represented by “n”, carriage return is represented by “r”, and so on. To use these characters into regular ASCII context, we have to escape them using the backward slash() character. This chapter illustrates escaping of special characters. Escaping “” The following example matches the pattern “”. [jerry]$ echo ”str1str2” | sed -n ”/\/ p” On executing the above code, you get the following result: str1str2 Escaping “n” The following example matches the new line character. [jerry]$ echo ”str1nstr2” | sed -n ”/\n/ p” On executing the above code, you get the following result: str1nstr2 Escaping “r” The following example matches the carriage return. [jerry]$ echo ”str1rstr2” | sed -n ”/\r/ p”
Sed – Overview
Stream Editor – Overview ”; Previous Next 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. McMahon wrote a general-purpose line-oriented editor, which eventually became SED. SED borrowed syntax and many useful features from ed editor. Since its beginning, it has support for regular expressions. SED accepts inputs from files as well as pipes. Additionally, it can also accept inputs from standard input streams. SED is written and maintained by the Free Software Foundation (FSF) and it is distributed by GNU/Linux. Hence it is often referred to as GNU SED. To a novice user, the syntax of SED may look cryptic. However, once you get familiar with its syntax, you can solve many complex tasks with a few lines of SED script. This is the beauty of SED. Typical Uses of SED SED can be used in many different ways, such as: Text substitution, Selective printing of text files, In-a-place editing of text files, Non-interactive editing of text files, and many more. Print Page Previous Next Advertisements ”;