Changes between Initial Version and Version 1 of MaintenanceGuidelinesTips


Ignore:
Timestamp:
09/10/10 13:46:14 (11 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MaintenanceGuidelinesTips

    v1 v1  
     1== Sed: Stream Editor ==
     2Search/Replace:
     3{{{
     4sed 's/old/new/g' input.txt > output.txt
     5}}}
     6Faster:
     7{{{
     8sed '/old/ s/old/new/g' input.txt > output.txt
     9}}}
     10
     11Do on a folder full of files:
     12{{{
     13#! /bin/sh
     14# Source files are saved as "filename.txt.bak" in case of error
     15# The '&&' after cp is an additional safety feature
     16for file in *.txt
     17do
     18cp $file $file.bak &&
     19sed 's/foo/bar/g' $file.bak >$file
     20done
     21}}}
     22
     23Insert paragraph:
     24 * e.g. search for lines `#include <termios.h>' and then write:
     25{{{
     26#ifdef SYSV
     27#include <termios.h>
     28#else
     29#include <sgtty.h>
     30#endif
     31}}}
     32
     33Now, for writing the same script on one line, the -e mechanism is needed... what follows each -e can be considered as an input line from a sed script file, so nothing kept us from doing:
     34{{{
     35sed -e '/#include <termios\.h>/{' \
     36-e 'i\' \
     37-e '#ifdef SYSV' \
     38-e 'a\' \
     39-e '#else\' \
     40-e '#include <sgtty.h>\' \
     41-e '#endif' \
     42-e '}'
     43}}}
     44
     451-liners:
     46 * http://www.student.northpark.edu/pemente/sed/sed1line.txt
     47
     48Tutorial:
     49 * http://sed.sourceforge.net/grabbag/tutorials/do_it_with_sed.txt
     50
     51Collected resources:
     52 * http://sed.sf.net/
     53
     54----
     55MaintenanceGuidelines