8 Replies Latest reply on Sep 17, 2009 6:18 AM by pretendermadafaka

    help with little script using grep

    pretendermadafaka

      i am a begginer but i guess this will not be a problem for somebody who is experienced...

       

      i am working with a lot of files that have tags. tag for italic text, tag for centered text and so on, i manage to

      get regular expression to work and to do all of these things with find/change dialog, but i would like to

      automate all of it..

       

      so for example i have part of the text that need to be italic that is enclosed in underscores like this _something that needs to be italic_

      and i have this regular expression that takes care of it _[A-Za-z0-9,;\-\?\(&!\):'". ]+_

       

      finds all the matches and applies the text style i want.

       

      how to do that with script? thanks in advance.

        • 2. Re: help with little script using grep
          Marc Autret Level 4

          Use FindChangeByList.jsx (with 'grep' findType).

           

          @+

          Marc

          • 3. Re: help with little script using grep
            pretendermadafaka Level 1

            ok, ok tried that, i opened FindChangeList.txt and changed one line and uncommented it

            here is who it looks:

             

            grep  {findWhat:"_[A-Za-z0-9,;\-\?\(&!\):'. ]+_"}  {applied paragraph style:paragraph style "boldanditalic"} {includeFootnotes:true}  finad and change to ita

             

            and it doesnt work

             

            i tried some of the text examples and they do work...what is going on? is there any simple test to try?

             

            (this regex works in find/change dialog)

             

            thanks again for the effort

            • 4. Re: help with little script using grep
              Marc Autret Level 4

              I think you need to escape the backslashes:

               

              { findWhat : "_[A-Za-z0-9,;\\-\\?\\(&!\\):'. ]+_" }

               

              Just a question, why not using this:

               

              { findWhat : "_[^_]+_" }

               

              @+

              Marc

              • 5. Re: help with little script using grep
                pretendermadafaka Level 1

                oh, you are write your expression work like a charm "_[^_]+_"

                the point is that i needed something fast and didnt know regex very well, and i am still a beginner..

                also, this works only in find/change dialog but not when i try to run a script ;( here is the line that i uncomented in the FindChangeList.txt

                 

                grep  {findWhat : "_[^_]+_"}  {changeTo:"^_"} {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:true}     description

                 

                i am not sure do i need stuff enclosed in third pair of parethesis...

                 

                anyhow, i save this file and ran the script from indesign...nothing happens

                maybe it is a bug...i tried some of the lines that deal with text and that worked like a charm but grep dont.

                 

                thanks for helping me.

                • 6. Re: help with little script using grep
                  pretendermadafaka Level 1

                  ok, i made it to work with countless tries, and it works but only first time, and i undo and run script again it doesnt work (text does but grep dont)

                  i then need to restart indesign to make it work again...what a hell is going on???

                   

                  how to make this work as it should?? thanks guys!

                  • 7. Re: help with little script using grep
                    [Jongware] Most Valuable Participant

                    Going back to your first GREP, search for this

                     

                    _([A-Za-z0-9,;\-\?\(&!\):'". ]+)_

                     

                    and replace with

                     

                    $1

                     

                    (with formatting in italic and/or your style) will do the formatting and remove the underscores at the same time. Only if you are totally sure the underscores are balanced, use

                     

                    _([^_])_

                     

                    -- if there is only one single unbalanced one, it'll mess up your text.

                    It should work correct in the interface; to put it into the findreplace script file, double the backslashes -- that's all.

                    • 8. Re: help with little script using grep
                      pretendermadafaka Level 1

                      thanks everybody, i manage to get it work taking into account what was written here...it all comes down to this:

                       

                      cs3 findchangelist script messes up indesign, i am using cs4 version and it doesnt give any problems

                       

                      line that i am using for italic is:

                       

                      grep    {findWhat:"_[A-Za-z0-9,;\\-\\?\\(&!\\):'\".~b/]+_"}    {appliedFont:"Adobe Garamond Pro", fontStyle:"Bold Italic", pointSize:13}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true}    //Comment

                       

                       

                      thanks again!

                       

                      @[Jongware]

                       

                      thanks, i am back to the old grep!