File: subst

package info (click to toggle)
saclib 2.2.8-6.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,872 kB
  • sloc: ansic: 40,932; csh: 1,190; asm: 541; awk: 320; sh: 246; perl: 116; makefile: 98; sed: 48
file content (33 lines) | stat: -rwxr-xr-x 783 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /bin/tcsh

# USAGE:
#   subst [-b] <sed substitution expression> <file names>
#
# FUNCTION
#   The sed substitution expression is applied globally to every file.
#   The format of this expression is 
#         /regular expression/replacement string/
#   For more information see sed(1).
#     If option "-b" is set, the original files are renamed with the 
#   extension ".bak", otherwise the original files are replaced.

if ("$1" == "-b") then
  set backup
  set sedexp="$2"
  set names=3
else
  unset backup
  set sedexp="$1"
  set names=2
endif
if ($#argv < $names) then
  echo "USAGE:"
  echo "  subst [-b] <sed substitution expression> <file names>"
  exit
endif

foreach i ($argv[$names-])
  mv $i $i.bak
  sed -e "s${sedexp}g" $i.bak > $i
  if (! $?backup)  rm $i.bak
end