0

I'm trying to cut a string until it's first specified characters. in this case, it's first Latin letter.

I tired this. It kind of works but sometimes shifts 1 or more characters.

f=$(echo $f | tail -c $((${#f}+-$(expr index "$f" [azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN])+2)))

take this string as example: ã%82¹ã%83%91ã%83¼ã%82¯ã%83«__original_ver.__-Your_name.mp3

I want to get: original_ver.__-Your_name.mp3 I tend to get this instead: ver.__-Your_name.mp3

Is there a better method? if so, some explanation is always welcome.

1 Answer 1

1

You can use extended globbing:

f=$(shopt -s extglob; LC_ALL=C; echo "${f##+([^[:alpha:]])}")
f=$(shopt -s extglob; LC_ALL=C; echo "${f/#+([^[:alpha:]])}")

or sed:

f=$(LC_ALL=C sed -r 's/^[^[:alpha:]]+//' <<< "$f")

Setting LC_ALL to C is mandatory, otherwise [[:alpha:]] might match wrong characters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.