Server Administration
  Home arrow Server Administration arrow Stream Editor in the UNIX Shell
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SERVER ADMINISTRATION

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

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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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:

    Option

    What it means

    -e

    The script we define as an argument

    -f

    The script is inside a file

    -n

    Do not print on the output after processing the stream

    -r

    Work with the extended regular expressions

    -i

    Edit the file itself

    -s

    If we give multiple inputs, work with the files individually

    -g

    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


     

    SERVER ADMINISTRATION ARTICLES

    - Understanding Awk in the UNIX Shell
    - Stream Editor in the UNIX Shell
    - Processes in the UNIX Shell
    - Migrating from Windows to Wine
    - Wine: Not Another Emulator
    - Preventive Measures to Block SSH Attacks
    - Monitoring Temperatures with Cacti
    - Cacti: RRDTool-based Graphing Solution
    - Network Magic 5.0 Review
    - Netfilter and Iptables Overview
    - Installing and Configuring Squid
    - Clickfree PC Backup Systems Compared
    - Squid, the Caching Proxy
    - Regular Expressions in the Unix Shell
    - Source Code Version Control Solutions





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek