Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

src_replace_word.sh 820 B

You have to be logged in to leave a comment. Sign In
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
  1. #!/usr/bin/env bash
  2. #
  3. # Script to do a simple source-code substitution where we
  4. # wish to replace one word with another word throughout all
  5. # C source and include files. E.g.,
  6. #
  7. # admin/src_replace_word.sh GMT_MSG_LONG_VERBOSE GMT_MSG_INFORMATION
  8. #
  9. if [ ! -d cmake ]; then
  10. echo "Must be run from top-level gmt directory"
  11. exit 1
  12. fi
  13. if [ $# -ne 2 ]; then
  14. echo "usage: admin/src_replace_word.sh oldword newword"
  15. exit 1
  16. fi
  17. # Set temporary directory
  18. TMPDIR=${TMPDIR:-/tmp}
  19. # 1. Find all source files with word $1 in them
  20. find -E src \
  21. -regex '.*\.(c|h|in)' \
  22. -exec grep -H $1 {} \; | \
  23. awk -F: '{print $1}' | sort -u > ${TMPDIR}/$$.tmp.lis
  24. # 2. Update the files and replace $1 by $2
  25. while read f; do
  26. sed -i.bak "s/$1/$2/g" $f
  27. rm -f $f.bak
  28. done < ${TMPDIR}/$$.tmp.lis
  29. # 3. Clean up
  30. rm -f ${TMPDIR}/$$.tmp.lis
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...