Vijay81 has asked for the wisdom of the Perl Monks concerning the following question:
Hi All, Am trying to substitute a comma in place of space in a line but till find the pattern. First part able to do but don't know how to do the part 2. Any help please
Script reads files(*.bat) from a perticular directory and read the content and substutite space with comma. bat file will have the pattern "-1". now i need subsutitue comma till find this pattern
bat file content :Main script content :01 fines name 2222 -P sws -1 reee.tee rrt 02 fi si 2232 -P sqww -1 re.wqw ttf
output file should look like :#!/usr/bin/perl use warnings; use strict; use Class::CSV; my ($csv, $inputfilename, $resultfile, $fh, $line, $dir, $fp, $count); $dir = 'C:\TestData'; open $resultfile, '>>', 'input.csv' or die "Can't open file: $!"; foreach $fp (glob("$dir/*.bat")) { #printf "%s\n", $fp; open ($fh, "<", $fp) or die "can't read open '$fp':"; while ($line = <$fh>) { #$line=~s/-l//; $line=~ s/ /,/g; print $resultfile $line; print $resultfile "\n"; print $line; } } close $fh or die "can't read close '$fp':";
01,fines,name,2222,-P,sws -1 reee.tee rrt 02,fi,si,2232,-P,sqww,-1 re.wqw ttf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl substitue till found pattern in aline
by rjt (Curate) on Dec 02, 2012 at 18:33 UTC | |
by pushtaev (Sexton) on Dec 03, 2012 at 06:26 UTC | |
by rjt (Curate) on Dec 03, 2012 at 08:57 UTC | |
|
Re: perl substitue till found pattern in aline
by johngg (Canon) on Dec 02, 2012 at 19:24 UTC | |
by Vijay81 (Acolyte) on Dec 03, 2012 at 08:36 UTC |