3 ms·
Extending your example above, how would you get a result of racing.champion or polish.ostrich ?
by ZenoArrow 9y ago
Extending your example above, how would you get a result of racing.champion or polish.ostrich ?
- Xophmeister 9y agoYou'd have to do it twice, using a temporary variable: $ name="polish.ostrich.racing.champion" $ temp="${name#*.}" $ echo "${temp#*.}" racing.champion That's if you want it generic (i.e., splitting on "." characters). In one shot, you could make the pattern more specific: $ echo "${name#*ostrich.}" racing.champion ...or use something like sed or awk: $ awk 'BEGIN {FS=OFS="."} {print $(NF-1), $NF}' <<< "${name}" racing.champion
- mbudde 9y ago${name%.*.*} polish.ostrich ${name#*.*.} racing.champion