You are not logged in.
Hi there,
I want to filter files that contain only a fixed number of digits, but not more (at least not in after the digits).
For example, I have
01.mp3
02.mp3
test10.txt
test000110101010.txt
04.flac
and for n=2 I want to get all files except 'test000110101010.txt'.
The following is not working, and I'm a total newb regarding regular expressions
ls -l | grep '^-' | awk '{print $9}' | grep '([0-9]\{2\})[^0-9]\{2\}'
Thanks for help.
Regards,
drm
Offline
I have no idea at all why you are doing `ls -l` or the `awk`...
$ ls *.txt
003.txt 01.txt 02.txt test04.txt test050test.txt
$ ls *.txt | grep -E '(^|[^0-9]+)[0-9]{2}([^0-9]+|$)'
01.txt
02.txt
test04.txt
Offline
Thanks!! ls -l and such was just stupid
Offline
You might want to make your life easier using find -regex in the future...
Offline
How about this, a bit harder with "edge detection" though:
shopt -s nullglob
ls -d1 [0-9][0-9] [0-9][0-9][^0-9]* *[^0-9][0-9][0-9] *[^0-9][0-9][0-9][^0-9]*
edit: added [0-9][0-9]
Last edited by Procyon (2011-02-04 13:44:22)
Offline
Thanks!
I wrote a python script to scan e.g. a music folder for missing files and needed to extract the file numbers from the files to get the "highest" number.
You can get it from here: http://pastebin.com/Sg9yDHiw (Python3, expires in 1 month)
Regards,
drm
Edit: found a bug
Last edited by drm00 (2011-02-04 13:57:43)
Offline