Server Administration

  Home arrow Server Administration arrow Stream Editor in the UNIX Shell

Stream Editor in the UNIX Shell
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1

    Table of Contents:
  • Stream Editor in the UNIX Shell
  • How does it work?
  • Sed Addresses
  • Sed Commands
  • The hold space and whole scripts



    Stream Editor in the UNIX Shell

    (Page 1 of 5 )

    Making a change sometimes takes a great effort coupled with a great sacrifice. At other times, though, it simply calls for a little adjustment of what we already have. The stream editor does just this. Since inside the UNIX shell, the universal language spoken is the text stream, with the help of this tool you can make some easy and fast modifications to the shell. If you are interested in what you can change and how you can change it with the stream editor, you will have to read this article.

    This article is part of my series related to shell programming in UNIX. Therefore, I will build on the fact that you can already write a script and run it inside a terminal. In addition, you should also know how to handle the control mechanism of the UNIX shell. All of these things are explained in my previous articles, so if by chance you missed them just search them up and embrace their knowledge.

    The structure of this article is as follows. First, I will present the syntax of the command. This will be followed by a general description of how this command works. Finally, I will present a few commands, separated into often-used and rarely-used groups, and those related to the hold puffer.

    Of course, I will include examples for all this to help you understand what I'm trying to explain. The ultimate goal is that you understand how it works. The sed is the acronym for the stream editor. You can already figure out that with this tool, you can edit streams of data. By this, I refer especially stream texts.

    The tool will read line after line of a text and make changes to it on request, or  simply let it all through. The syntax of the tool is the following:

    sed [options] 'script' [input files]

    Where the options can be:


    What it means


    The script we define as an argument


    The script is inside a file


    Do not print on the output after processing the stream


    Work with the extended regular expressions


    Edit the file itself


    If we give multiple inputs, work with the files individually


    At all the replacements, use the global option

    From the upper table you can already see that the "script" part is not obligatory as an argument. If you want it, you can write it inside a file. The stream editor has its own commands to process the text. This will be the subject of the third section of the article. We can enter this into a separate file, and this will be the script. If you choose to use the file, you will need to enter every command on a new line and start the script with the following line:

    #!/bin/sed -f

    This will allow you to later call the sed without appending the -f option each time, as follows:

    sed script_file alfa

    This will execute on every line of the alfa file the commands found inside the script_file. However, this is a simplified approach. To find out more about how the stream editor works, read the next page.

    More Server Administration Articles
    More By Gabor Bernat

    blog comments powered by Disqus


    - SSH Case Studies: Gateway Hosts
    - SSH Case Studies: More on Pine and SSH
    - SSH Case Studies: Pine and IMAP
    - SSH Case Studies: More on the Passive Mode
    - SSH Case Studies: Network Address Translation
    - SSH Case Studies: The Passive Mode
    - SSH Case Studies: The FTP Protocol
    - SSH Case Studies: Batch Jobs, FTP and SSH
    - SSH Case Studies: Agents and Authentication
    - SSH Case Studies
    - Server Responses to Client Communication
    - Authentication in Client/Server Communication
    - Client/Server Communication
    - Understanding Awk in the UNIX Shell
    - Stream Editor in the UNIX Shell

    Developer Shed Affiliates


    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap