Hi all,
I have a problem with a text file which I am trying to strip all the tabs out of, and replace with their equivalent space (I know I could probably do this outside of Perl but I'm sure that there must be a way to do it and I not gonna give up till I find it.) The file looks like this :
{some random text} 9.99 9.999 9.999 9.999 9.9999 9.9999 {more text} 9.99 *9.999 *9.999 9.999 9.9999 9.9999 {even more text} 9.99 9.999 9.999 *9.999 *9.9999 *9.9999 ..this goes on for 12 or so columns..
Basically the first two columns, the text and three sig-fig number are fixed, but the following columns sometimes have a *preceding them, and sometimes don't.
All the table is at present tab-delimited.
<nbsp> So, the problem is, how do I strip out the '\t's?
If it weren't for the '*' I could simply use a "s/\t/ \1/g" or something of that nature. But having the *s means in where there is a *, I need one less space than where there isn't one.
So, I tried this:
perl -1 "while (<>) s/\t(\*w+)/ \1/g;s/\t\s(w+)/ \1/g;print}" +myfile
Which did - <bold> absolutely nothing </bold>. The tabs are all still there.
I know I'm probably being a complete retard, but is there an obvious way to do this that I've missed out on?

Thanks,
Mike

In reply to Conditionally converting tabs to spaces by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.