12.07.2015 Views

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

Red Hat Enterprise Linux 5 Administration Unleashed

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

248CHAPTER 11Automating Tasks with ScriptsDocumentation for Perl can be found in the many man pages that come with the perlpackage. Start by executing the man perl command. The main Perl man page provides alist of other man pages and their purposes. More information and further documentationcan be found at http://www.perl.org/.Writing Scripts with SedA stream editor, Sed, reads the input of text sequentially line by line and processes itthrough a set of text transformation rules. All the rules are applied to the text with onepass of the text file from start to finish. Sed can be used on the command line from thesed command or it can be called from a script such as a Bash script, which was discussedearlier in this chapter. The sed RPM package must be installed to use Sed. Install it from<strong>Red</strong> <strong>Hat</strong> Network if it is not already installed. Software installation instructions can befound in Chapter 3.To use a Sed rule from the command line, use the following format, which saves the newcontent in a separate file:sed -e ‘’ original.txt > newfile.txtAlternatively, you can output the contents of a file and pipe it through Sed:cat original.txt | sed -e ‘’ > newfile.txtTo apply Sed rules to a file “in-place,” use the following format (the changes are made tothe same file):sed -i -e ‘’ file.txtNOTEIf you do not redirect the results into a new file, it is displayed to standard out, ordisplayed on the command line before returning to the command prompt.Sed commands can also be called from a script file by using a Bash script. The first line ofthe file must be#!/bin/bashAfter that, the syntax for calling the command is the same as from the command line.Refer to the “Executing Commands in a Bash Script” section earlier in this chapter forfurther explanation of the file format.Listing 11.10 provides some sample Sed commands that can be invoked from thecommand line. They can also be executed from a script as previously described. Linesbeginning with # in Listing 11.10 are comments to explain the commands.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!