You can actually use expr
in POSIX shell do what you need as well, e.g.
while read -r line; do
len=$(expr match "$line" [0-9][0-9]*[A-Za-z]*)
[ "$len" -gt '0' ] && expr substr "$line" 1 $len ||
printf "%s\n" "$line"
done < file
With your data in file
, just cut and paste the above into the command line, e.g.
$ while read -r line; do
> len=$(expr match "$line" [0-9][0-9]*[A-Za-z]*)
> [ "$len" -gt '0' ] && expr substr "$line" 1 $len ||
> printf "%s\n" "$line"
> done < file
one1
2two
45end
note: while this is a solution using expr match
and expr substr
, the sed
solutions are more efficient as you will spawn a separate subshell on each expr
call. (but it is good to know the alternatives...)