[SOLVED]sed: regex repeated pattern

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)

Escaping '{' and '}' helps:
sed 's@.*\([0-9]\{4\}\).*@\1@'
Last edited by karol (2010-04-05 16:24:22)

Similar Messages

  • Variable in regex replace pattern

    Hi,
    I need to use a variable in a regex replace pattern - how can I do it? Specifically, I need to pass arguments to a shell script that then uses that argument in a replace pattern:
    #!/bin/bash
    #$1 now holds the argument
    sed 's/searchpattern/replace_pattern_with_variable$1/g' file1 > file2
    when I run this, the replace pattern uses $1 as a literal string "$1" and not the variable value. How can I change this?
    Thanks!
    Ingo

    Hi Ingo,
       As Vid points out, the issue is that single quotes protect strings from shell interpretation. You need to have the dollar sign, '$', visible to the shell or it won't read what follows as a variable name. Using double quotes works because the shell "reads through" those.
       However, complex regular expressions can contain lots of characters that the shell interprets. These can be quoted individually by backslashes but the use of backslashes in regular expressions is complex enough without the addition of shell interpretation. I find it easiest to keep the single quotes and only expose the part of the string that the shell needs to interpret.
       The shell doesn't have a special string concatenation character. All you have to do is to put the strings beside each other with nothing in between and the shell will concatenate them. Therefore it's possible to write your example as:
    sed 's/searchpattern/replace_pattern_with_variable'${1}'/g' file1 > file2
    That is, one closes the single quote right before the variable and then resumes it immediately afterward. The shell will put these quoted strings together with the contents of the variable just as it would with double quotes but you still enjoy the protection of single quotes around the rest of the string!
    Gary
    ~~~~
       P.S. Perl's master plan (or what passes for one) is to take
       over the world like English did. Er, as English did...
          -- Larry Wall in <[email protected]>

  • Seamless repeating pattern - using embedded images with clipping masks

    Hi forum,
    We struggle a bit creating a seemless repeating pattern that includes embedded images with clipping masks applied.
    Our pattern is a 550x550mm black square with various embedded inserted on top. All of these images have Clipping Masks applied to hide unwanted areas.
    These images are placed so they create a seamless repeating pattern and this includes areas that overlap the square.
    Once we create a swatch from this pattern the repeatable area becomes too big as it includes the unwanted areas hidden by the clipping masks.
    Because the repeatable area is now too big it's actually not repeatable.
    We tried various things in order to solve this issue. Pathfinder/crop to delete the unwanted areas in the images etc.
    None of them worked good enough.
    We though of just livetracing the images, but due to the complexity this is not an option.
    Do we really have to do our "cutting" in Photoshop or do you know any fancy tricks for issues like this?
    Appreaciate your insight
    Kenneth

    Kenneth,
    You may try the destructive deed, with the Clipping Mask selected:
    1) In the Transparency palette/panel dropdown list select anything but Normal (Multiply is fine),
    2) Object>Flatten Transparency, just keep the defaults including 100% Vector,
    3) Shudder.
    This should reduce the size to the Bounding Box of the Clipping Path.

  • Offset feature not creating clean lines when repeating pattern/image

    Using PSE11, I have been working at several repeating patterns using the offset feature, but am having a problem with images not having a clean seam when connecting different layers to create the pattern. 
    Any recommendations?
    Thanks.
    Here's a screenshot of an example..

    Again, how you feel is really of no interest at all. How you feel will not get you one whit closer to solving the problem you have, and will probably even get in the way.  If you have a problem we can help. Any scolding I do is about your aggression. Think of it this way. If someone stops you in the street and politely asks the way to the train station you'll be a lot more likely to help him or her than a person swearing at how awful the street maps are and generally being aggressive.
    Obviously you don't get the fundamental difference, or you wouldn't have the problem. And yes, your photos can remain exactly as you organised them, but if that's what you wanted why did you then use iPhoto? You used the file manager for this job on windows, now you're trying to use a database for the job on your Mac. So you've switched OS and then the method of managing your photos.
    Now you need to decide. Do you want to work exactly as you did on Windows? If so, don't use iPhoto, just use the Finder (that's the file manager on the Mac.) That's what you did on Windows.
    If you want to use iPhoto, and so take advantage of the extra features that it has, then you'll need to rethink your way of working just a little but we can get very close to what you have now. But it will not be identical.
    If you don't want to use iPhoto just copy your folders of images over to the Mac. Job done. Otherwise, come back and let us know how your folders are arranged and we can try help you adapt that to iPhoto.

  • How can I make a column of sums out of a repeating pattern of 24 changing numbers

    How can I make a column of sums out of a repeating pattern of 24 changing numbers in Numbers.
    I have a long list of 8760 numbers of which I need to take the sum (and store in a column) of each 24 numbers.

    Here's one way. I've reduced the example, taking groups of five numbers from a set of 20. I've used 3 as the data number in all cases to make the sum easily recognizable.
    Original column of numbers in Data::column A.
    Data::B2 (and filled down): =QUOTIENT(ROW()+3,5)
    This adds 3 to the row number, then divides by 5, returning the quotient and ignoring the remainder.
    The result is a 'group number' for each group of five rows.
    Sums of each group are reported in the Sums table.
    Sums::A2 (and filled down): =ROW()-1
    Sums::B2 (anf filled down): =SUMIF(Data::$B,A2,Data::$A)
    For your example, assuming the 8760 numbers are listed in column A of a table named Data, starting at cell A2:
    Add a second column to the table (column B).
    In B2 enter the QUOTIENT formula above, with these two revisions:
    =QUOTIENT(ROW()+22,24)
    Fill down to all cells in the column.
    Provided you have named the first table "Data", both formulas in the Sums table will be as written above. You will need to extend the Sums table to 366 rows (including the Header row) to accommodate all 365 groups of 24.
    Regards,
    Barry
    PS: For details on the functions used, see the iWork Formulas and Functions User Guide. You can download the guide via the Help menu in Numbers '09.

  • How do I make a repeat pattern in Photoshop CC?

    I am trying to make a seamless repeat pattern in photoshop. I used to be able to do this in older versions of Photoshop by adjusting the position of my artboard in Filter -> Other -> Offset.
    Now I can't seem to adjust the offset by adjusting the pixels according to the size of my artboard, but I have to choose a pixel number between -1182 and +1182 instead?
    For instance, if my artboard is 100px I used to be able to set it to 50px so the artboard shifts halfway to the right. Now I have to set it at (1182 : 4=) 295px to get my artboard to that same position.
    Plus, when I use 'wrap around' the objects in my artboard don't appear on the other side of the artboard as should be the case.
    What is going on? Does anyone know how I can easily make a repeat pattern in Illustrator now? Is there something like 'Pattern maker" for Photoshop cc,  like the one that used to be available for older versions of PS but is now disabled for Photoshop CC?
    Thanks a bunch! 

    https://www.google.com/search?sourceid=chrome-psyapi2&rlz=1C1CHFX_enUS546US546&ion=1&espv= 2&ie=UTF-8&q=photoshop%20tutor…

  • How can I create a symbol filled with a repeating pattern?

    Hey there. Iam trying to make a symbol and it should have a repeating pattern (jpg, png, gif) in the back. It should be 100% widht and height and I will move it on the main stage.
    Any ideas for that?
    I just have this code to put it in the background for the whole page. This works pretty good but it is not the thing I am looking for actually.
    $("#Stage").css("background-image","url(images/pattern_small.jpg)","background-repeat","re peat")
    put in Stage/CompositionReady
    1000 thanks in advance!!!

    You need to add the snippet
    sym.getSymbolElement().css({'background-image':'url(images/sprinkles.png)','background-rep eat':'repeat'});
    in the symbol creation complete event.
    Here is a sample
    https://drive.google.com/file/d/0B2k82B_Y-fXCMTdTSi16VHp4em8/edit?usp=sharing

  • Converting sed regex to Java regex

    I am new to reguler expressions.I have to write a regex which will do some replacements
    If the input string is something like test:[email protected];value=abcd
    when I apply the regex on it,this string should be changed to test:[email protected];value=replacedABC
    I am trying to replace test.com and abcd with the values i have supplied...
    The regex I have come up with is in sed
    s/\(^.*@\)\(.*\)$/\1replaceTest.com;value=replacedABC/i
    Now I am trying to get the regex in Java,I would think it will be something like (^.*@\)(.*\)$\1replaceTest.com;value=replacedABC
    But not sure How i can test this.Any idea on how to make sure my java regex is valid and does the required replacements?

    rsv-us wrote:
    Yep.Agreed.
    Since that these replacements should be done in a single regex.Note that the sed replacement I posted is really made of two replacements! Just like your Java solution would.
    I think once we send this regex to the third party,they will haev to use either sed or perl(will perl do this replacements,not sure though) to get the output.
    Since we are not sure what tool/software the third party is going to use,I was trying to see how i can really test this.Then I read about sed and this regex as is didn't work,so,I had to put all the sed required / and then the regex had become like s/\(^.*@\)\(.*\)$"/1replaceTest.com;value=replacedabcd/iAgain: AFAIK that does not work. I tried it like this:
    {code}$ echo test:[email protected];value=abcd | sed 's/\(^.*@\)\(.*\)$"/1replaceTest.com;value=replacedabcd/i'and the following is returned:test:[email protected] that we will have to send the java regex to the third party,I was trying to see how i can convert this sed regex to java.If I am right,with jave regex,we won;t be able to all the finds and replacements in a single regex..right?...If this is true,this will leave me a question of whether I need to send the sed regex to the thrid party or If I send java regex,they have to convert that to either sed or perl regex.
    One more question,can we do thse replacement in perrl also,if so,what will the equivalent regex for this in perl?
    I can't understand what you are talking about. The large amount of spelling errors also doesn't help to make it clearer.
    Good luck though.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Unwanted paths showing after cropping to make a repeat pattern tile.

    I'm trying to make a repeat pattern tile (using CS5 on Windows 7), but when I crop the pattern, the expanded paths underneath become visible as on the flowers below.
    This is what I did after creating the artwork:
    Used the rectangle tool to make a box with fill/stroke directly on top of the artboard..
    Select all > Expand (selecting stroke only, not fill)
    Deselect the cropping box and grouped the remaining objects.
    Reselected the cropping box and grouped all objects
    Pathfinder > Crop
    I'm guessing it may have something to do with the fact I used a gradient on the flowers but have no idea how to resolve it. Does anyone have any suggestions? Thanks.
    PS. Please excuse me if this explanation is really poorly worded...I've only ever used Illustrator for fashion technical sketches so my knowledge is pretty limited.

    Followed your advice above, and hopefully it will work. The only issue is it's a bit time consuming they way I'm doing it, as I'm having to delete the outermost objects first, then delete any objects which are partially inside the rectangle, otherwise I find some of the objects inside the rectangle are deleted too:
    At the moment for the objects that are partially inside the box, I'm using the scissors tool to cut the path where it crosses the rectangle. Is there an easier solution to this problem?

  • Repeating pattern question

    I’m trying to make a repeating pattern that includes a teapot image that I filled with a repeating rose pattern background. After everything has been reflected evenly on all axis, I then try to drag into the swatches panel. However, for some reason when I try to drag this pattern into the swatches panel, illustrator won’t do it. It will do it if I remove the tea pots and tea cups that have that repeating background pattern, but not when it’s there. Any idea what’s going on?
    It seems like ai is confused that I’m trying to make a repeating pattern with an image (the teapot)  that has a repeating pattern for the background.

    Select the teapot and cup and go to Object>Expand before you drag back into the swatches panel.

  • Problems with getting repeating patterns to display properly

    Using Oracle's Map Definition Tool I am trying to import repeating patterns through the "import image" functionality, found under "map metadata --> styles --> area", but I am having problems getting them to work properly (i.e. they don't repeat as they should). Part of the problem is the poor quality of repeating patterns images that where send my way.
    Therefore I have 2 questions I hoped someone here could answer me:
    1) Is there an easily accessible collection of decent+ quality repeating patterns somewhere on the web where I could look for patterns to use?
    2) What is the image resolution used by the Oracle Map Definition Tool, or in other words, what is the minimum resolution I need to make sure the pictures are to make them downscale properly to a single pattern image through the "import image" functionality?

    For starters, you could try any of the pattern images/icons available in your popular word/graphics applications such as Word, Powerpoint, or Adobe. For instance in PowerPoint you can find a set of Patterns under Format Auto Shape > Fill > Fill Effects > Pattern. You can generate your own pattern images that closely follow the design of these from PowerPoint.
    When you import an image, as long as you make sure the preferred width/height of the image is set to identical with the real width/height of the image itself, MapViewer will not attempt any scaling during rendering, thus preserving the native resolution of your pattern image.

  • Can anyone help me with a repeating pattern that is staggered?

    Can anyone help me with a repeating pattern that is staggered and must be aligned perfectly while staggered. Is there a way to do this? I keep staggering it by eyeball and need it to be accurate and each row is offset.
    My art board is 19.25x11.50 I have a repeating logo and name underneath (hard to see) I am setting this up for a print design to go onto tissue paper for insert into a shoe box. Any help is greatly appreciated?
    Thanks,

    Option drag your object horizontally to make a copy or use Move and copy if you need a precise increment. The hit Cmd+D a few times to make duplicates with the same spacing.
    Hit Enter again and make a note of the increment on a piece of paper. Cancel.
    Select everything and use the same increment, now in a vertical direction, to make 2 further copies.
    Take the middle row and move it horizontally by half of the increment. This means that the circles in the middle row are positioned horizontally half way between those in the other two rows.
    Draw your defining rectangle so that its corners are on the centres of those 4 circles. (This gives you its right size but you may possibly need to move it a bit.) Send it to the back of your stack.
    Drag those 8 circles and the rectangle to your Swatches panel.
    (If you’re on Windows read Ctrl instead of Cmd and Alt instead of Option.)

  • Repeating Pattern in a sequence

    I am making an encrypting program in java and I have a little problem.
    I need to know how I can find repeating patterns in a sequences of numbers:
    For Ex:
    {1,2,3,1,2,3}
    repeating pattern is 1,2,3 and the pattern occurs twice
    {1,2,3,2,3}
    no repeating pattern
    {5,0,0,5,0,0}
    500 is the repeating pattern and occurs twice
    I hope you get the idea. What the best way to do this efficiently? I think there is an algorithm already designed for this.. but not sure.
    Appreciate any help,
    John

    This little program can detect a period in a list of ints
    [not optimal but functional :^]:
    public class PeriodDetector {
        public static boolean isCyclic(int list[], int period) {
            for (int i=period; i<list.length; i++) {
                if (list[i-period]!=list[i ]) {
                    return false;
            return true;
        public static int detectPeriod(int list[]) {
            for (int period=1; period<=list.length/2; period++) {
                if (list[0]==list[period] && list.length%period==0) {
                    if (isCyclic(list, period)) {
                        return period;
            return -1;
        public static void main(String argv[]) {
            int list[] = new int[argv.length];
            for (int l=0; l<list.length; l++) {
                list[l] = Integer.parseInt(argv[l]);
            System.out.println("Period..." + detectPeriod(list));

  • Cloning - repeating patterns

    I recently moved from CS to CS4, and found the clone tool worked a little bit differently. In CS, when the clone tool source location ran over an already cloned area in a single drag, you would get a repeating pattern. I found this useful in when the source area was small, and worked great for repeating areas like grass and bricks.  However, with CS4, when the clone tool source location runs over an already cloned area in a single drag of the mouse, it ignores the cloned area and clones the original source that was underlying the cloned area.  This makes it impossible for me to create large repeating areas out of limited source areas.
    I have looked through all the buttons and features of the clone tool, and can't seem to find one that will let me operate like CS did.  Also, this topic is a bit hard to do a web search on, as I get lots of hits on clone but none of them answer my question.
    Any help here would be greatly appreciated, as I am having trouble adjusting to the new way the clone tool works, though I do like all the new clone features.

    Thank you, Bill.  This is driving me nuts.  I could swear all my previous version did this, as it was my favorite trick to use.  For example, if I had a straight object like a curb, fence, belt, post, etc. I could select a target and starting point close together but on same line, and then drag TOWARDS the sample point I had selected and make a curb go on forever and ever, even through other objects.  I seem to recall this only worked when target and starting point were close together and I dragged toward the starting point without lifting the mouse button - all one stroke.  I used this trick daily, and loved it.  I just tried aligned and unaligned on my CS4, and neither did it.  I might have to dig out my older copy of PS and find another computer to try it on, otherwise it is going to keep nagging me...

  • Angled Stripes Repeating pattern

    Vertical  or horizontal stripes are no problem, but they are angled cannot get a seamless repeating pattern. I tried using snppaing 2 lines and running a blend between them, thininig the stroke is half in and half out so this should.
    You can see the seam below. Any idea how to do this with 8° rotation on the line?

    Tried rotating a couple different ways could not get some type to fill with angled stripes. I don't want to use the type as a mask over a big page of stripes, as I am looking to incorporate this into my designing with appearance stacks.

Maybe you are looking for

  • SSO to partner application running under IIS

    Hi, We have a complete set-up for 9iAS Release2 where some applications are running. In parallell we have an application running under IIS, and would now like to enable the IIS application as a partner application to 9iAS letting the 9iAS SSO server

  • Error 5566 on Web Service

    We have simple SharePoint 2010 Firm enthronement with one Front End, one SQL servers. All our custom databases and web services are on second SQL server. All our web based Info Path forms with web services suddenly stopped working with 5566 error. Th

  • Retrieve music after sync. help again plz!!!

    My music seems to have disappeared after my iPod automatically synced itself. How do I retrieve it?

  • HELP!!! Itunes recognizes only 22gb available for a 60gb ipod.

    I have a 4th generation 60gb ipod and a week ago all of my music was erased and I could do nothing to remove the folder/exclamation mark icon from my ipod. It was stuck in disk mode for a week and yesterday it finally started working. I unistalled al

  • List of differences between Ipod & Itunes

    Is there a simple way to list the differences between the content of my Ipod and Itunes? So that I can just add what is new. I am using a manual sync. Thanks.