Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • ls hsli* | head -1 | sed 's/[0-9]*\.[0-9]*//' or even ls hsli* | head -1 | sed 's/[0-9.]\+/./' Commented Feb 26, 2015 at 19:56
  • Will try it @Costas thanks. The command got rid of the digits all together and the output is hsli.h5. Commented Feb 26, 2015 at 19:59
  • 1
    Of course, without ls, you can do: set -- hsli*; set -- "${1#*.}"; echo "${1%.*}" Commented Feb 26, 2015 at 20:03
  • 1
    @Vesnog - ok, so do printf %.02f\\n ".$(earlier cmd)" - it's probably better than echo anyway. Or for the second version just ...;echo "0.${1%.*}". Oh, and maybe add a -s switch to cut so you only work with filenames that definitely contain the right amount of . dots. Commented Feb 26, 2015 at 20:07
  • 1
    @Vesnog - well, for the second one, you might want to do a test first before the echo (in case the filename you search for doesn't exist or doesn't have the right number of dots). I'll do an answer. Commented Feb 26, 2015 at 20:17