Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm wondering if anyone knows of an app that would allow me to auto-sequence massive lists and the like. I'm finding it hard to explain! Basically I would like to do stuff like:

<p class="item_1_link">
 <a href="item_1.html">
  <img src="picture_1.jpg">
 </a>
</p>

<p class="item_2_link">
 <a href="item_2.html">
  <img src="picture_2.jpg">
 </a>
</p>

...and so on, without typing it out.

The above isn't an example of the code I'm trying to create of course, it's an example of the type of text manipulation I'm looking for!

Sorry this is a bit vague but any pointer in the right direction would be appreciated!

share|improve this question

closed as not a real question by KronoS, Oliver Salzburg, Canadian Luke, Nifle, techie007 Jun 30 '12 at 19:16

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Really easy to do with code... dont know how else to do it. –  soandos Jul 26 '11 at 19:53
add comment

4 Answers

up vote 0 down vote accepted

Your question is definitely vague, but perhaps check out the macro features in TextMate? My understanding is you want to generate the same template but change the text such as item_1_link, item_1.html, and picture_1.jpg. You can create such snippets in TextMate where you would be able to make a keyboard shortcut that generates the template and then just ⇥ (tab) across to each field that you want to type your text in.

The image below shows an example for creating a new function in Python.

TextMate Bundle Editor

share|improve this answer
    
This is exactly the kind of thing I was looking for, thank-you! –  Cordial Jul 28 '11 at 8:22
add comment

BBEdit's Clipping system can invoke scripts (see chapter 12 of the BBEdit 10 manual) which could handle something like this easily.

For something as trivial as your example, I would use simply use a Regex find and replace in BBEdit or TextMate. List the numbers, one per line, then search and replace ^(.*)$ with something like:

<p class="item_\1_link">
   <a href="item_\1.html">
     <img src="picture_\1.jpg">
   </a>
</p>

If there were many numbers I'd generate the text with a script. If it was something I'd have to use often, then I'd make a clipping.

Usually I'd have the data in a list, comma separated perhaps, that I want to transform. Regex is the quick and easy way to do this.

share|improve this answer
add comment

I'd use a scripting language

#!/usr/bin/perl
use strict;
use warnings;

print <<END for (0..7);
<p class="item_${_}_link">
 <a href="item_$_.html">
  <img src="picture_$_.jpg">
 </a>
</p>
END
}

Produces

<p class="item_0_link">
 <a href="item_0.html">
  <img src="picture_0.jpg">
 </a>
</p>
<p class="item_1_link">
 <a href="item_1.html">
  <img src="picture_1.jpg">
 </a>
</p>
<p class="item_2_link">
 <a href="item_2.html">
  <img src="picture_2.jpg">
 </a>
</p>
<p class="item_3_link">
 <a href="item_3.html">
  <img src="picture_3.jpg">
 </a>
</p>
<p class="item_4_link">
 <a href="item_4.html">
  <img src="picture_4.jpg">
 </a>
</p>
<p class="item_5_link">
 <a href="item_5.html">
  <img src="picture_5.jpg">
 </a>
</p>
<p class="item_6_link">
 <a href="item_6.html">
  <img src="picture_6.jpg">
 </a>
</p>
<p class="item_7_link">
 <a href="item_7.html">
  <img src="picture_7.jpg">
 </a>
</p>
share|improve this answer
1  
Or Ruby: 1.step(3) {|i| puts "<p class=\"item_#{i}_link\">\n <a href=\"item_#{i}.html\">\n <img src=\"picture_#{i}.jpg\">\n </a>\n</p>\n\n"}. Generating static HTML and writing this kind of temporary text processing scripts are both great ways to learn a scripting language. –  Lri Jul 26 '11 at 23:36
add comment

You can do it with code, as the other answers point out. Or you can do it with OpenOffice Spreadsheets using just formulas and copy and paste. This is a great and easy way to avoid any real programming and still achieve your goals. Excel will work too, of course.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.