File: replace

package info (click to toggle)
freeciv 3.2.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 286,372 kB
  • sloc: ansic: 484,137; cpp: 37,716; sh: 10,365; makefile: 7,424; python: 2,938; xml: 643; sed: 11
file content (28 lines) | stat: -rwxr-xr-x 1,058 bytes parent folder | download
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
#!/usr/bin/env bash
#/***********************************************************************
# Freeciv - Copyright (C) 2017-2023
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2, or (at your option)
#   any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#***********************************************************************/

if test "$1" = "-h" || test "$1" = "--help" || test "$3" = "" ; then
  echo "Usage: $0 <path> <string to replace> <replace with>"
  exit
fi

find "$1" -name "*.[ch]" |
  (while read FILE ; do
     if grep "$2" "$FILE" >/dev/null ; then
       echo "Updating $FILE"
       sed "s/$2/$3/g" "$FILE" > "$FILE.new"
       mv "$FILE.new" "$FILE"
     fi
   done )