views:

20

answers:

3

Hi, not necessarily a programmer question but I need to enter a TAB after every 84th character of a text. I'm trying to do it in InDesign but I don’t see an option for this. Is there a good application to do this?

Preferably Mac OS X compatlible but Windows XP is fine too.

Thank you very much!

A: 
$ cat file.txt  | sed 's/\(.\{84\}\)/\1       /g'

If you have problems entering the tab, try Ctrl-V, tab.

Sjoerd
A: 
cat file.txt  | perl -p -e 's/(.{84})/\1\t/gs'

Note that the 's' modifier at the end also matches newlines, so the counter spans over multiple lines and also counts newlines as characters.

Sjoerd
A: 

I decided to try a different approach. Using PHP, you can make a small app that will accept a chunk of text, parse it, and allow you to copy it. Basically a web app that you can submit the text to and it will add the tabs.

This would just need to be hosted on a web server with PHP enabled, then it will work on both Mac and Windows. If you don't have a web server, you can install a local copy of WampServer or XAMPP on a machine somewhere and give it a try. (XAMPP has an installer for Mac.)

<html>
    <head>
        <title>84th character tab inserter</title>
    </head>
    <body>
        <?php
        if ($_POST['text'] != "")
        {
            $text = $_POST['text'];
            $i = 0;
            $output_text = "";
            for (; $i < strlen($text); $i+=84)
            {
                $output_text .= substr($text, $i, 84) . "\t";
            }
            $output_text .= substr($text, $i);
            echo '<pre>';
            echo $output_text;
            echo '</pre>';
        }
        else
        {
            ?>
            <form method="POST" action="">
                <textarea name="text" cols="100" rows="10" onclick="javascript:this.value = '';">Paste input text here...</textarea>
                <br />
                <input type="submit" value="Parse" />
            </form>
            <?php
        }
        ?>
    </body>
</html>
JYelton