Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Sed

Sed

Ratings: (0)|Views: 128 |Likes:
Published by anon-550457
A stream editor which edits text files in place using commands & regular expressions
A stream editor which edits text files in place using commands & regular expressions

More info:

Published by: anon-550457 on Aug 10, 2007
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

04/29/2011

pdf

text

original

 
Sed - An Introduction
Last update SunSep 24 19:44:00 EDT 2006Thanks to Keelan Evans for spotting some typos.Thanks to WimStolker aswell.
Table of Contents
The Awf ul Truth about sedThe essential command: s for substitutionThe slashas a delimiterUsing &as the matched stringUsing 1 to keep part of the patternSubstituteFlags/g - Global replacementIs sed recursive?/1, /2, etc. Specifying which occurrence/p - printWrite toa file with /w filenameCombining substitution flagsArguments and invocation of sedMultiplecommands with -e commandFilenames on the commandline sed -n: no printingsed -f scriptnamesed in shell scriptQuotingmultiple sed lines in the C shellQuotingmultiple sed lines in the Bourne shellA sed interpreter scriptSed CommentsPassing arguments into a sed scriptUsing sed in a shell here-is documentMultiple commands and order of executionAddresses and Ranges of TextRestricting to a line numberPatternsRanges by line numberRanges by patternsDelete with dPrinting with pReversing the restriction with !Relationships between d, p, and !
 
The q or quit commandGrouping with { and }Writing a file with the 'w' commandReading in a file with the 'r' commandSunOS and the # Comment CommandAdding, Changing, Inserting new linesAppend a line with 'a'Insert a line with 'i'Change a line with 'c'Leading tabs and spaces in a sed scriptAdding more than one lineAdding lines and the pattern spaceAddress ranges and the above commandsMulti-Line PatternsPrint line number with =Transform with yDisplaying control characters with a lWorking with Multiple LinesUsing new lines in sed secriptsThe Hold BufferExchange with xExample of Context GrepHold with h or HKeeping more than one line in the hold bufferGet with g or GFlow ControlTesting with tAn alternate way of adding commentsThe poorly undocumented ;Passing regular expressions as argumentsCommand SummaryIn ConclusionCopyright 2001,2005 Bruce Barnett and General Electric CompanyAll rights reservedYou are allowed to print copies of this tutorial for your personal use, and link tothis page, but you are not allowed to make electronic copies, or redistribute thistutorial in any form without permission.
Introduction to Sed
How to use sed, a special editor for modifying files automatically. If you want towrite a program to make changes in a file, sed is the tool to use.
 
There are a few programs that are the real workhorse in the Unix toolbox. Theseprograms are simple to use for simple applications, yet have a rich set of commandsfor performing complex actions. Don't let the complex potential of a program keepyou from making use of the simpler aspects. This chapter, like all of the rest, startwith the simple concepts and introduces the advanced topics later on.A note on comments. When I first wrote this, most versions of sed did not allowyou to place comments inside the script. Lines starting with the '#' characters arecomments. Newer versions of sed may support comments at the end of the line aswell.
The Awful Truth about sed
Sed 
is the ultimate
s
tream
ed
itor. If that sounds strange, picture a stream flowingthrough a pipe. Okay, you can't see a stream if it's inside a pipe. That's what I getfor attempting a flowing analogy. You want literature, read James Joyce.Anyhow,
sed 
is a marvelous utility. Unfortunately, most people never learn its realpower. The language is very simple, but the documentation is terrible. The Solarison-line manual pages for
sed 
are five pages long, and two of those pages describethe 34 different errors you can get. A program that spends as much spacedocumenting the errors than it does documenting the language has a serious learningcurve.
Do not fret!
It is not your fault you don't understand
sed 
. I will cover
sed 
completely. But I will describe the features in the order that I learned them. I didn'tlearn everything at once. You don't need to either.
The essential command: s forsubstitution
Sed 
has several commands, but most people only learn the substitute command:
s
.The substitute command changes all occurrences of the regular expression into anew value. A simple example is changing "day" to "night:"sed s/day/night/ <old >newI didn't put quotes around the argument because this example didn't need them. If you read my earlier tutorial, you would understand why it doesn't need quotes. If you have meta-characters in the command, quotes are necessary. In any case,quoting is a good habit, and I will henceforth quote future examples. That is:sed 's/day/night/' <old >new

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->