Hi all, new to the forum and rather a noob in perl matters. Here's the problem. I'd like to process /var/log/messages on a linux system and substitute all whitespaces for commas up to a certain position (to be able to export the file to a csv format). Here's a sample from /var/log/messages:
Oct  1 13:23:25 smoothwall-swe3 kernel: Allocating PCI resources starting at 10000000 (gap: 08000000:f6c00000)
Oct  1 13:23:25 smoothwall-swe3 kernel: Built 1 zonelists
Oct  1 13:23:25 smoothwall-swe3 kernel: Kernel command line: BOOT_IMAGE=SmoothWall ro root=804 ramdisk_size=8192 no-scroll panic=30
Oct  1 13:23:25 smoothwall-swe3 kernel: Enabling fast FPU save and restore... done.
Oct  1 13:23:25 smoothwall-swe3 smoothd: Loading Plugins for Module "/usr/lib/smoothd/sysinstall.so
I want to replace all whitespaces up to the one after the bold words included (after kernel: and smoothd:). What I have tried so far has proved useless, namely
#!/usr/bin/perl open (FILE,"</var/log/messages") || die 'Unable to open log file'; open (TMP, ">/tmp/messages.csv") || die 'Unable to write to file'; while (<FILE>) { $_ =~ s/\s{1,6}/,/; print TMP $_; }
It just replaces the first occurrence, after the leading Oct. Any help would be greatly appreciated, since googleing has proved rather frustrating. TIA

In reply to perl substitution difficulty by nanouk

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.