You are not logged in.
Hi all,
Currently I'm struggling with bash script for automatic presorting and converting of photos from camera.
While man page says that {} is repeated of previous pattern it does not work for me. Here is the example (basically I want extract year of the timestamp).
% exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp
Image timestamp : 2008:05:09 10:25:02
% exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp | sed 's@.*\([0-9]{4}\).*@\1@'
Image timestamp : 2008:05:09 10:25:02
% exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp | sed 's@.*\([0-9]{3}\).*@\1@'
Image timestamp : 2008:05:09 10:25:02
And this one works
% exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp | sed 's@.*\([0-9][0-9][0-9][0-9]\).*@\1@'
2008
If I need repeated m times this is not acceptable. How to deal with this?
Last edited by ogronom (2010-04-05 16:26:54)
Offline
' exiv2 20080930--DCIM/100CANON/IMG_0002.JPG| grep timestamp | cut -c 19-22' might do as well.
Offline
I'm not interested in workarounds (there is one posted above). I'm wondering why {} does not work. Most porobable my understanding of the man re_syntax is incorrect, I just wonder why.
Offline
Escaping '{' and '}' helps:
sed 's@.*\([0-9]\{4\}\).*@\1@'
Last edited by karol (2010-04-05 16:24:22)
Offline
Found
Silly issue. instead of {} one should use \{\}
Offline
Thanks, karol
Offline