Swap words order
Learn / Forums / General InDesign Topics / Swap words order
- This topic has 9 replies, 5 voices, and was last updated 8 years, 1 month ago by Matt Isaac.
-
AuthorPosts
-
-
February 12, 2016 at 3:18 am #81907Riccardo RiguzziMember
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
code2Between “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
code1I 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. -
February 12, 2016 at 3:56 am #81908Niels JÌürgen PedersenParticipant
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!
-
February 12, 2016 at 4:04 am #81909Riccardo RiguzziMember
: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 :)
-
February 12, 2016 at 7:01 am #81911David BlatnerKeymaster
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.
-
February 12, 2016 at 9:03 am #81918Matt IsaacParticipant
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 -
February 14, 2016 at 11:53 pm #82017Riccardo RiguzziMember
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…
-
February 15, 2016 at 2:04 am #82020Chris ThompsonMember
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. -
February 15, 2016 at 6:23 am #82030David BlatnerKeymaster
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.
-
February 15, 2016 at 9:39 am #82036Matt IsaacParticipant
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.
-
-
February 15, 2016 at 6:53 am #82034Chris ThompsonMember
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.
-
-
AuthorPosts
- You must be logged in to reply to this topic.