Content added Content deleted
imported>DrOwl No edit summary |
imported>DrOwl |
||
(11 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
= Beispiele = |
|||
Sed A Stream Editor |
|||
Alle Zeichen "=F1" und "=F2" in einer Datei durch "X" ersetzten |
|||
cat text.txt | sed -r s/"(=F1)|(=F2)"/X/g |
|||
oder, um [[UUOC]] zu vermeiden: |
|||
Sed is a "non-interactive" stream-oriented editor. It is stream-oriented because, like many UNIX programs, input flows through the program and is directed to standard output. (vi, for instance, is not stream-oriented. Nor are most DOS applications.) Input typically comes from a file but can be directed from the keyboard. Output goes to the terminal screen by default but can be captured in a file instead. Sed works by interpreting a script specifying the actions to be performed. |
|||
sed -r s/"(=F1)|(=F2)"/X/g text.txt |
|||
---- |
|||
Examples |
|||
[http://www.student.northpark.edu/pemente/sed/sed1line.txt HANDY ONE-LINERS FOR SED] |
|||
to change all instances for "OldString" with "NewString" |
|||
== Inline replace for Solaris== |
|||
cat file.txt | sed ' {s/OldString/NewString/g} ' > newfile.txt |
|||
This is my 5 line backup and in-line replace for Solaris (will work on a lot of other *nix too) |
|||
[[Bash_Scripts#Archive_files|archive]] is a nice script use to backup files ;) |
|||
<pre> |
|||
# for x in $(grep -l kgl-fwall03-eth8 *) ; |
|||
do archive $x ; mv $x $x.tmp ; |
|||
sed s/kgl-fwall03-eth8/kgl-app-tier-fw-eth8/ $x.tmp > $x ; |
|||
rm $x.tmp |
|||
done |
|||
</pre> |
|||
You can change this to an inline delete by fidling the sed line e.g. |
|||
<pre> sed "/_asigra /d" $x.tmp > $x ; </pre> |
|||
= Man-Page = |
|||
s = Substitute , g = Global |
|||
<man>sed</man> |
|||
{{manpage}} |
Latest revision as of 08:01, 9 September 2010
Beispiele[edit]
Alle Zeichen "=F1" und "=F2" in einer Datei durch "X" ersetzten
cat text.txt | sed -r s/"(=F1)|(=F2)"/X/g
oder, um UUOC zu vermeiden:
sed -r s/"(=F1)|(=F2)"/X/g text.txt
Inline replace for Solaris[edit]
This is my 5 line backup and in-line replace for Solaris (will work on a lot of other *nix too) archive is a nice script use to backup files ;)
# for x in $(grep -l kgl-fwall03-eth8 *) ; do archive $x ; mv $x $x.tmp ; sed s/kgl-fwall03-eth8/kgl-app-tier-fw-eth8/ $x.tmp > $x ; rm $x.tmp done
You can change this to an inline delete by fidling the sed line e.g.
sed "/_asigra /d" $x.tmp > $x ;
Man-Page[edit]
<man>sed</man>