-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschReplaceStr.sh
More file actions
38 lines (38 loc) · 1.11 KB
/
schReplaceStr.sh
File metadata and controls
38 lines (38 loc) · 1.11 KB
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
34
35
36
37
38
#!/bin/sh +x
#
# Copyright (C) 2021 Uysan
#
# This program is free software which is
# licensed under the terms of the GNU General Public License v2.
#
# Author: Selcuk Mustafa
#
which perl > /dev/null
if [ $? -eq 0 ]; then
if [ $# -eq 2 ] && [ ! -z "$1" ] && [ ! -z "$2" ]; then
count=`ls -1 *.sch 2>/dev/null | wc -l`
if [ $count != 0 ]; then
for f in *.sch; do
grep -q "EESchema Schematic File Version 2" $f || grep -q "EESchema Schematic File Version 3" $f ||
grep -q "EESchema Schematic File Version 4" $f
if [ $? -eq 0 ]; then
count=`grep -c $1 $f`
if [ $count != 0 ]; then
#echo "$1 found in $f"
perl -i -psle '$rcnt++ if s/$from/$to/g; END{if($rcnt != 0){ print "Replaced $from with $to $rcnt times in $ARGV"} else { print "No replacement done in $ARGV"}}' -- -from=$1 -to=$2 $f
#else
#echo "$1 not found in $f"
fi
else
echo "Wrong file type. $f should be EESchema Schematic File Version 2 or greater."
fi
done
else
echo "No sch file found in current directory."
fi
else
echo Usage: $0 old_string new_string
fi
else
echo "Please install perl."
fi