Reputation: 198348
I'm a newbie of bash/fish, and found some string operations are quite difficult, like:
and so on. Although I can find all kinds of solutions for most of the cases, but I find it not easy to remember or use.
So I just wonder if there is any command/library which supports most of the common string operations, suppose its name is mystr
, so I can just use it like this:
mystr --to-upper somestring
mystr --starts-with sss somestring
mystr --contains bbb sometring
mystr --suffix somestring
mystr --trim somestring
mystr --match "some.*" somestring
mystr --find-match "some(.*)" somestring $1
, I mean just get the matched part in (.*)
Upvotes: 3
Views: 149
Reputation: 18561
It's not in a release, but top-of-tree fish has a nice new strings
feature: https://github.com/fish-shell/fish-shell/issues/156
Other than that, you would generally use a mishmash of external commands. This is Unix, after all!
echo something | tr "[:lower:]" "[:upper:]"
echo stuff | grep -q '^stu'
echo stuff | grep -q 'tuf'
echo stuff | grep -q 'uff$'
echo ' hello ' | sed 's/^[[:space:]]*//g' | sed 's/[[:space:]]*$//g'
echo somestring | grep -q '^some.*$'
echo somestring | grep -q 'some.*'
Upvotes: 3