May 6, 2015

Sed Command in Linux - Print Lines in a File

Here is the brief introduction of the Super sed:

  • sed stand for Stream EDitor and it being based on the ed editor, it borrows most of the commands from the ed. It was developed by Lee E. McMahon of Bell Labs.
  • sed offers large range of text transformations that include printing lines, deleting lines, editing line in-place, search and replace, appending and inserting lines, etc.
  • sed is useful whenever you need to perform common editing operations on multiple lines without using 'vi' editor.
  • Whenever sed is executed on an input file or on the contents from stdin, sed reads the file line-by-line and after removing the trailing newline, places it in the "Pattern space", where the commands are executed on them after conditions (as in case of regex matching) are verified, and then printed on the stdout.

Printing Lines from a File using sed

Before we start, just remember two points:

  1. sed"p" command lets us print specific lines based on the line number or regex provided.
  2. sed with option -n will suppress automatic printing of pattern buffer/space. So, we would want to use this option. (Explained in later section)

Read more at YourOwnLinux

Click Here!