This didn't make it work completely. I have found the way to do it. First I remove all the returns and make one file of it. After that I build in again returns looking for a certain pattern. If somebody can make it <CR> shorter and knows how I can skip to make intermediate file and create straigt away the target file it is welcome. Pieter Here is the code :

#!perl -w use strict; use FileHandle; my $file = "c:/perl/training/test/common.grb"; #source file my $file1 = "c:/perl/training/test/test5.txt"; #intermediate file, jus +t contain one long line my @users = readFile($file); for(@users) { chomp; s/\s+/ /g; } writeFile("c:/perl/training/test/test5.txt", @users); my @newUsers = readFile($file1); for (@newUsers) { s/(.)G57/$1\nG57/g; } writeFile("c:/perl/training/test/test6.txt", @newUsers);> #target fil +e, each line start with G57 sub readFile { my ($fileName) = @_; sysopen(F, $fileName, O_RDONLY) or die "\nCannot open #<CR> $file: $!\ +n"; my @fileContents = <F>; close(F); return @fileContents; } sub writeFile { my ($file, @contents) = @_; if(-e $file) { unlink $file or die "\nunable to remove $file: $!\n"; } sysopen(F, $file, O_RDWR | O_EXCL | O_CREAT, 0666) or die "\nCannot cr +eate $file: $!\n"; print F @contents or die "\nCannot write to $file: $!\n"; close(F) or die "\nCannot close filehandle - $file: $!\n"; }

Edit 2001-03-21 by mirod: added code tags


In reply to Re: (tye)Re: How to look for patterns in a file and create a CR by juo
in thread How to look for patterns in a file and create a CR by juo

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.