Hi! Trying to replace srings in file.Input Csv file contains 5 columns. First column contains name. If name ends with AS then it should be repalced with "1" ($line =~ s/(.*\sAS)/1/g;) when AS is not present then the value should be "0"!!!. 2 column- no need to change but has to be moved in first place and the first column needs to moved in 5th place with replaced strings. 3;4;5 colums I use substitute to change strings. If there is no value in 3;4;5 colums then I need to insert "0" (dont know how to do that) At the end of the line there should be added 1 more column - todays date "strftime(".%Y%m%d", localtime);" !!! Input file:
E. name;E.serial;E. kive;E. bilanss;E. emp 01 Norme OÜ;10818160;less 1 miljoni;less 1 miljoni; 1 AGENCY OÜ;10652268;less 1 miljoni;less 1 miljoni;1 - 5 emp 1. JALASTAAP;70007295;;; 101 SYSTEMS OÜ;10825652;3 - 10 miljonit;1 - 3 miljonit; 15075 OÜ;10399876;1 - 3 miljonit;less 1 miljoni;1 - 5 emp 5SVARA AS;11036261;;; 1QA OÜ;10614794;less 1 miljoni;less 1 miljoni;
output file:
10818160|1|1|0|0|2010-05-12| 10652268|1|1|5|0|2010-05-12| 70007295|0|0|0|0|2010-05-12| 10825652|10|3|0|0|2010-05-12| 10399876|3|1|5|0|2010-05-12| 11036261|0|0|0|1|2010-05-12| 10614794|1|1|0|0|2010-05-12|
#! C:\Perl64\bin\perl use strict; use POSIX qw(strftime); my $add_date = strftime(".%Y%m%d", localtime); my $output_tag = (".csv"); my $failid='C:\\ROOT_DIR\\Inspektor\\insp_file.aa'; my $dest = "C:\\ROOT_DIR\\Inspektor\\test\\"; if (open(FAILIDcnt, $failid)) { while(my $input = <FAILIDcnt>) { chomp($input); my $output = $input; open(IF, 'C:\\ROOT_DIR\\Inspektor\\' .$input) or next; open(my $dest,"> $dest".$output) or die "Can't open $dest: $! +"; while(my $line = <IF>) { $line =~ s/less 1 miljoni/1/g; $line =~ s/1 - 3 miljonit/3/g; $line =~ s/3 - 10 miljonit/10/g; $line =~ s/10 - 20 miljonit/20/g; $line =~ s/20 - 50 miljonit/30/g; $line =~ s/50 - 100 miljonit/100/g; $line =~ s/100 - 250 miljonit/102/g; $line =~ s/250 - 500 miljonit/103/g; $line =~ s/500 milj - 1 miljard/104/g; $line =~ s/over 1 miljardi/105/g; $line =~ s/1 - 5 emp/5/g; $line =~ s/6 - 15 emp/15/g; $line =~ s/16 - 25 emp/25/g; $line =~ s/26 - 50 emp/50/g; $line =~ s/51 - 100 emp/100/g; $line =~ s/101 - 250 emp/250/g; $line =~ s/251 - 500 emp/500/g; $line =~ s/501 - 1000 emp/1000/g; $line =~ s/over 1000 emp/1001/g; $line =~ s/;/|/g; # needs if or something $line =~ s/(.*\sAS)/1/g; # every other case should be 0 elseif !!! print $dest "$line"; } close($dest); close(IF); } close (FAILIDcnt); }

In reply to substitute strings by tannx

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.