I got a lot of files whose names are like this:
tmp1.csv
tmp32.csv
tmp9.csv
tmp76.csv
...
They are in the same dir, and I want to extract the numbers in the file name. How can I do that in bash
?
PS
I tried grep
, but can't make it. Also I tried ${filename##[a-z]}
. Are they the right way to go?
ls |grep -o "[0-9]\+"
Example:
$ ls *.csv
3tmp44.csv newdata_write.csv tmp1.csv tmp2.csv
$ ls *.csv |grep -o "[0-9]\+"
3
44
1
2
Edit:
From grep man page:
Basic vs Extended Regular Expressions
In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).
That is why you need to use \+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With