Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Grep or scripting

Return to Member Forum

  • Author
    Posts
    • #55665

      I have a text file consisting of 51,000 race participants. Each person is represented by a single line consisting of the surname followed by a comma, a space, then the first name, then a tab, then a finishing position, then a tab, then a time.

      Example

      Mackie, James(Tab)11750(tab)1:14:02

      My problem in prepping this for agate publication in a newspaper is the limited line length available for the name, about 22 characters on average. After that, I need to force a soft return after the surname. Problem is, sometimes the surname is long, sometimes the first name, sometimes both — it's the total length of the name that is the issue.

      Is there any way in GREP to examine everything before the tab and IF it exceeds a certain length, insert a soft/forced line ending after the space.

      Or is this getting into scripting (which is an area I know less than absolutely nothing about)

      I did this chore manually yesterday, which took two hours (with a deadline looming), and swore never to go through that again.

      Thanks

    • #55668

      From beginning of line to first tab, with 22 characters or more of non-tabs, replacing that tab with a soft return:

      Find

      ^([^t]{22,})t

      Replace

      $1n

      (although you might want to add the tab again in the replacement line, so your next data is aligned the same as non-soft-returned lines).

      It won't work perfectly; if there is a single name with lots of i's and no m's, it will broken while not necessary; and if you have a single long name with lots of m's, you'll need to spot those by eye. But I think these stand out of the crowd, and in any case there shouldn't be much of these (if there are too much remaining, decrease the number of minimal characters).

    • #55687

      I will try this

      Thank you

      Is there any way in GREP to test up to the tab, BUT force the soft return after the comma (after the surname, but not the first/Christian name). Or would that mean Javascript?

    • #55688

      You would think that's not possible, would you? So did I :-)

      But, amazingly, this seems to work!

      Find:

      ^(?=[^t]{22,})([^,]+,) ?(.*t)

      Replace with:

      $1n$2

    • #55697

      Bonjour Jongware

      Your first coding works perfectly

      Your second does not. I just get a “no match found” error

    • #55701

      I just tried again, and it works for me …

      Did you type it in, or copied it? There is a single space before the 2nd question mark, to remove an optional space between the comma and the following text. Without the space .. oh okay, without the space it also works :-)

      If you cannot get it to work, eliminate by removing entire bracketed groups from the right: first, see if

      ^(?=[^t]{22,})([^,]+,) ?

      finds anything at all, and if not remove the second group and test.

    • #55708

      Thanks, I'll try this over the weeknd.

      In any case, once the first search you suggested is run, it's a pretty simple second GREP search keying in on the /n to get exactly what I want.

    • #55709

      Oh, now I understand. No, you should not run my first GREP and then my 2nd. The 2nd try does (or rather, “should do” :-) ) all the work at once.

      Perhaps that's why you got a “not found”, where it worked for me — I started with your original data again.

Viewing 7 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads