Sublime Forum

[SOLVED] Tricky Find + Replace

#1

I have a tricky situation that I am not quite sure how to solve. I have a datable to be used with Jquery / Datatables that needs some formatting after exporting it from an excel pivot table.

    <tr>
        <td>AD</td>
        <td> $0.03 </td>
        <td>    </td>
        <td>    </td>
    </tr>
    <tr>
        <td>BD</td>
        <td> $0.05 </td>
        <td> $0.54   </td>
        <td> $5.32   </td>
    </tr>
    <tr>
        <td>CD</td>
        <td> $0.35 </td>
        <td> $0.59   </td>
        <td> $0.32   </td>
    </tr>

Each of the “td” will need to set a class name. The first in the “tr” would be class=“1”, second would be class=“2” etc etc.

I cant use a mass find replace on the entire “tr” block due to each “td” having unique values within.

Any ideas how to acheive this? I’ve got 16,000 lines of a data set that need to be adjusted.

Thanks!

0 Likes

#2

This looks like it’ll suit your needs

0 Likes

#3

This is how i’d do it using Sublimes multiple cursors.

0 Likes

#4

Hey @devcarlos - Both of those suggestions are definitely on the right track!

Only issue is that under each “tr” I’ve got about 25+ “tds” and the "td"s need to be each given a class name. So for instance, the first child td would need to be class=“1” and so on, but most imporantly, restarting the numbering under each tr.

Hope that makes sense! Its over 16,000 lines and oh boy am I begging for any easy method to learn here. =)

0 Likes

#5

silly question, but why do you need to assign the td elements a class, surely your CSS selector can just use nth-child?

0 Likes

#6

@kingkeith - The entire table is dataset for jquery datatable for a website. Ultimately each td is a stat for a column / category that I need to ultimately identify in order to allow the show / don’t show via filtering.

0 Likes

#7

Let me make sure I understand you before I try to come up with a solution. Is this what you mean?

    <tr class="1">
        <td = class="1">AD</td>
        <td = class="2"> $0.03 </td>
        <td = class="3">    </td>
        <td = class="4">    </td>
    </tr>
    <tr class="2">
        <td class="1">BD</td>
        <td class="2"> $0.05 </td>
        <td class="3"> $0.54   </td>
        <td class="4"> $5.32   </td>
    </tr>
    <tr class="3">
        <td class="1">CD</td>
        <td class="2"> $0.35 </td>
        <td class="3"> $0.59   </td>
        <td class="4"> $0.32   </td>
    </tr>
0 Likes

#8

@devcarlos Correct regarding the td classes. For the TR, unnecessary.

0 Likes

#9

Found a solution through a combination of Text-Pastry package, multiple cursors and some good ole Nokogiri.

Thanks for the direction!

1 Like

#10

Glad you solved it :slight_smile:

I actually steered away from Text Pastry and was looking for a CSS solution.

0 Likes