The awk utility is good for this. So are a number of other common system scripting utilities, including raw script programming and perl, but in this case, the awk solution is probably the simplest. You'd just set up a
pattern to match only the "ls" output lines and then use awk's builtin field-parsing abilities to extract the values.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.