Sed

From Hackepedia
Revision as of 05:03, 2 July 2008 by Pbug (talk | contribs) (New page: == Introduction == Sed stands for stream editor and it does just that, it edits a stream. There is many uses for it for example in the well known substitution mode. == sed and substitu...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

Sed stands for stream editor and it does just that, it edits a stream. There is many uses for it for example in the well known substitution mode.


sed and substitution

Using the s allows the results to be substituted like so:

echo one two three four five six seven eight nine | sed -e 's/one/bleep/g' -e 's/five/bleep/g'

would result in:

bleep two three four bleep six seven eight nine


sed and deleting

If I wanted to delete lines 1 through 46 the syntax would be so:

francisco$ sed -e '1,46d' /etc/passwd   
_postfix:*:507:507:Postfix Daemon:/var/empty:/sbin/nologin
testuser:*:1001:1001:test:/usr/home/testuser:/bin/ksh

You see the last two entries of a 48 line file.