Bash split strings :-)
For a little test script I’m writing I needed to split a line on a ‘;’ but preservere the “s and ’s, something that echo doesn’t like to do. Digging deeper into the bash docs I see that there are some handy string handling functions.
#!/bin/bash
line=’this “is†a command;this “is†a pattern’
COMMAND=${line%;*}
PATTERN=${line#*;}
echo $COMMAND
echo $PATTERN
And the output would be:
this “is†a command
this “is†a pattern
Source: http://anton.lr2.com/archives/2006/04/10/bash-split-a-string-without-cut-or-awk/