V
V
Vadim2021-04-06 21:33:40
linux
Vadim, 2021-04-06 21:33:40

How to remove all numbers, spaces and dashes at the beginning of a string - in any order?

Hello everyone,

I want to optimize this terrible string so that it only starts with a letter

extracted_file_name=$(printf '%s' "$extracted_file_name" | sed -e 's/^*//' | sed -e 's/^[0-9]*//g' | sed -e 's/^*//' | sed -e 's/^[0-9]*//g' | sed -e 's/^*//')


works, but ugly
Vadim

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xotkot, 2021-04-06
@Viji

it’s easier to go from the opposite, first remove everything that is not a letter
sed -e 's/^[^[:alpha:]]\+//'

V
Vadim, 2021-04-06
@Viji

in fact, probably so ... although not quite!

extracted_file_name=$(printf '%s' "$extracted_file_name" | sed -e 's/^*[0-9]*[-]*//')

for example, such cases do not take into account
extracted_file_name=" --- 123 234 abscdfgdgdfg.txt"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question