Swap words order

Learn / Forums / General InDesign Topics / Swap words order

Viewing 8 reply threads
  • Author
    Posts
    • #81907

      Hello,
      my name is Riccardo and I’ve just started a new job where I need to learn really fast all the things I have never used in inDesign (and I’m following some lectures on lynda.com about styles, GREP and working on big documents with a lot of tables and cross references…)

      I’m sorry to bother all of you but I’d like to know if it is possible to swipe two text lines… Let me explain.
      I have a table and, in one of the columns, I have all the rows with the following field:

      code1
      code2

      Between “code1” and “code2” I have a return “\n”.

      I would like to know if there is a way (maybe with find/replace) to swap these lines and to obtain the following result:

      code2
      code1

      I don’t know if I gave you all the information (or even if it is possible to automatically do what I’m trying to do) but thank you very much for any help.

      Regards,
      Riccardo.

    • #81908

      Search for “code2” and replace with “code1xxxx”
      Then search for “code 1” and replace with “code2”
      And then search for “code1xxxx” and replce with “code1”

      Voila: Lines switched!

    • #81909

      :D
      If it was so simple I would never bother to ask :)

      Probably I didn’t explain myself in the correct way.

      I have 87 “codeUP” (let’s call it this way) and 87 “codeDOWN”, and they are different. Example:
      ———-
      268951
      H1019
      ———-
      268681
      HY19001
      ————

      And I am looking for a way to switch their position to have:

      ———-
      H1019
      268951
      ———-
      HY19001
      268681
      ————

      Without having to go for every line and doing it by hand :)

    • #81911
      David Blatner
      Keymaster

      Are all the first codes “all numbers”? And are all the second codes start with the letter H (or HY) and end with numbers? You need to be extremely specific when searching with grep.

    • #81918
      Matt Isaac
      Participant

      This GREP expression may work for what you have.. but like David says, You need to be extremely specific when searching with grep. depending on your other coding this may leave some codes un-switched

      Find What:
      (\d+)\r(HY?\d+)

      Change To:
      $2\r$1

    • #82017

      Sorry for the late answer (and thank you very much for the replies!)

      All the first codes are numbers. The second codes start with a letter, but the letter isn’t always a H, it could be also a P, a S, a N etc…

    • #82020

      Is it possible to copy that single column out of the table, and then manipulate it separately, then re-insert it?
      If the column is consistent, you might be able to:
      convert the table column to text with suitable delimiters between the two entries in each row,
      re-convert that text to a two-column table (using those delimiters, so that the first element of each row is now in column 1 and the second element is in column 2),
      swap the order of the two columns…

      then reverse the process:
      re-convert to text,
      re-convert to a single column table,
      re-insert into the original table.

      Does that make sense? It’s almost harder to explain it than to do it.

      Good luck,
      Chris.

    • #82030
      David Blatner
      Keymaster

      Chris’s table solution might work, but I think Matt’s GREP idea is faster and easier. But I think I would use:
      Find: (^\d+$)\r(^\u+?\d+$)
      Replace: $2\r$1

      Make sure you have not applied formatting to the text first, because GREP find/change like this will mess it up.

      • #82036
        Matt Isaac
        Participant

        David,
        I’ve never come across a situation to where i needed to include the beginning\end of paragraph symbol for a grep search. Apart from changing “HY?” to “\u+?” for the obvious reason; could you tell me the difference in using, or not using, the additional beginning\end of paragraph from my expression to yours?

        Riccardo,
        A side note to David’s GREP expression.. If your codes use capital and lower case letters you may need to change “\u+?” to “[\l|\u]+?” otherwise leave his expression the way it is.

    • #82034

      Yes, I’d go with a GREP if possible – the GREP would be best so long as there’s a discernible consistent pattern to the *content*, while the table manipulation is a fallback – and works if there’s a discernible pattern to the *structure* (new lines/returns etc), but not the content.

      Chris.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.
>