First published at 03:56 UTC on March 11th, 2021.
If you're using subshells, grep, sed, and tr inside loops in your shell scripts, you might be able to use some built-in features of GNU Bash to dramatically speed those scripts up. Parameter expansion, globbing, and extended regular expression …
MORE
If you're using subshells, grep, sed, and tr inside loops in your shell scripts, you might be able to use some built-in features of GNU Bash to dramatically speed those scripts up. Parameter expansion, globbing, and extended regular expression (regex) matching can be used to replace a lot of string manipulation constructs, reducing or eliminating external commands that must be fork-exec'd and waited upon, including subshells and common simple uses of grep and sed to locate and clean up text strings. Also, sometimes it's better to write a small C helper program if you have a particularly "hot" chunk of script code, and an instance where I've done this instead of Bash optimizations is presented in the video.
This video illustrates four useful constructs:
String search-and-replace: ${VAR/search_term/replace_term}
Double-bracket globbing: [[ $VAR == *substring_to_match* ]]
Regex string matching: [[ $VAR =~ regex_to_match ]]
Line finding: while read X; do [[ $X == *string* ]] && break; done ‹ file_to_scan
Chapters:
00:00 Opening
00:24 Intro & Git log
03:31 Replace echo-sed with Bash search-and-replace
13:54 An alternative: write a C helper program
19:25 Replace grep -q with Bash regex matching
27:52 Globbing is faster than regex matching
28:23 Replace grep -m 1 with 'while read' loop
YouTube: https://www.youtube.com/c/JodyBruchon
BitChute: https://www.bitchute.com/channel/jodybruchon/
Personal/programming site: https://www.jodybruchon.com/
Video production site: http://www.gazingcat.com/
Computer repair site: http://nctritech.com/
SUPPORT LINKS
Ko-Fi: https://ko-fi.com/L3L02069D
SubscribeStar: https://www.subscribestar.com/JodyBruchon
Flattr: https://flattr.com/@JodyBruchon
PayPal: https://paypal.me/nctritech
LESS