0

I'm looking for the best way to search all the occurrences of a string and replace them with something related to the line number.

For example, line 857 must become:

z-index: 96;

where 96 = (linenumber +7) / 9.

And line 848 must become:

z-index: 95;

where 95 = (linenumber +7) / 9.

sample screenshot of my document

mskfisher
  • 3,291
  • 4
  • 35
  • 48
Jean Paul
  • 1
  • 1

1 Answers1

0

If you are willing to switch half way through to some kind of spreadsheet application, please, read on.

Using TextWrangler (4.5.11) with grep enabled for searches:

  • Start adding line numbers using TextWrangler's -> Text -> Add/Remove line numbers.
  • Search for ^[[:digit:]]+ (?!z-index)(.*)$ and replace with \t\1.
  • Search for ^([[:digit:]]+) and replace with =(\1+7)/9\t.
  • Mark everything and copy.

Sorry - no clue, how to calculate inside TextWrangler. Thus:

  • Paste into some spreadsheet application. (Did test with Google table and Excel. Might need to adjust formula if other software is being used.)
  • Wait for the formulas to be calculated.
  • Mark everything and copy.
  • Go back to TextWrangler. Paste replacing original selection.
  • Verify the calculations' result to persist.
  • Search for ^([[:digit:]]+)\t(\s+z-index: )0; and replace with \2\1.
  • Verify the file's content (and provide more detail if necessary to address the problem in full; significant chunk of data would facilitate proper testing…).
Abecee
  • 2,365
  • 2
  • 12
  • 20
  • @JeanPaul Did you have a chance to give the above a try? Any adjustments you would like to see? – Abecee Nov 12 '14 at 22:47