Using ls
I have a directory containing .jpg files like this:
Quote:
In this directory the files that start with an underscore "_" are thumbnails and the files without the leading underscore are full size pictures. In the script I'm writing I need to list only the full size pictures, the ones without the leading underscore. It's easy to list only the thumbnails by using: Quote:
Any ideas? Thanks. LocoMojo |
$ ls | grep -v _*.jpg
|
Hi Ashamril,
Thanks for your reply, but your suggestion didn't work. I got: Quote:
LocoMojo |
Try "ls [^_]*.jpg".
|
Quote:
That worked like a charm...thanks!!! What does that mean? I want to read about it, where would I find information about it in the man pages? Is it regex? Thanks again! LocoMojo |
You could use the file pattern [^_]*.jpg
i.e. ls [^_].jpg The "carat" symbol negates the character match if it is the first symbol. The grep example didn't work because you didn't have a wild card character after the underscore. ls | '^_.*\.jpg' There is a difference between the asterisk character in the shell, versus in a regular expression. An asterisk in the shell expands to any character or characters. In a regular expression, it expands to zero or more occurences of the previous character. Because the 'dot' character is used as a wild card in regular expressions, if you want to match the actual character, you need to escape it by preceding it with a backslash. |
jschiwal,
Thanks for that. I learned something new. I didn't know about the different uses of wildcards in the shell and regular expressions. I've never really gotten into learning about regular expressions. Obviously they're very useful so I should get into learning about it. Know of any good sources of information about regular expressions for beginners? Thanks again. LocoMojo |
The bash reference may have information on it.
Here is a Regular Expression tutorial on the web: http://www.grymoire.com/Unix/Regular.html A Linux Focus Article: http://www.linuxfocus.org/English/Ju...article53.html There is a book called "Linux Shells by Example" which may have the best examples and exercises on Regular Expressions. They are used for VIM, sed, awk and other programs. http://www.amazon.com/gp/product/013...lance&n=283155 Also, the O'Reilly book "Sed & Awk" has a chapter on Regular Expressions. The 1st Edition is available on the web. If you google for it you may find it. Here is an example that I have found useful. Suppose that you have downloaded several files in Pan, but because people aren't very original in naming them, you have many that look like: catpic.jpg catpic_copy_2.jpg catpic_copy_3.jpg. There may be several like that, and some may be duplicates. If there are duplicates, you want to get rid of them. Code:
for file in *_copy_[[:digit:]].jpg; do |
All times are GMT -5. The time now is 10:18 PM. |