in reply to Re^3: Replace value in the text file
in thread Replace value in the text file
I love to use the one you recommend but I am just a beginner so not sure how to apply See if you can help me to edit my code below I like to change the value in column one to a fix value. Any number should reduced by 1 except "1" becomes "P". I am trying to learn how to use map or grep not creating the hash, that the guys showed me. Thanks Macy
"Header1","Header2",Header3" "A123","1","valueB1" "B234","1","valueB2" "C345","2","valueB3" "D456","3","valueB4" "E567","4","valueB5" "F678","5","valueB6"
and the output should be
"Header1","Header2",Header3" "A123","P","valueB1" "B234","P","valueB2" "C345","1","valueB3" "D456","2","valueB4" "E567","3","valueB5" "F678","4","valueB6"
here is my code
open my $fh1,'<',"NRoomch.txt"; my @a = <$fh1>; my @arr; for $i (0..$#a){ my @b = split(/,/,$a[$i]); for $j (0..$#b) { $b[$j] =s~/"//g; if ($j==1 && my @arr = grep { $_ =~ /\"1"$/ } @b); @arr = map{$_ = "P"} @arr; else @arr = map {$b[$j] - 1} (1..$#b); print @arr; }; }; close($fh1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Replace value in the text file
by AnomalousMonk (Archbishop) on Jun 30, 2017 at 06:19 UTC | |
by mhoang (Acolyte) on Jul 01, 2017 at 02:16 UTC | |
|
Re^5: Replace value in the text file
by haukex (Archbishop) on Jun 30, 2017 at 08:59 UTC | |
by mhoang (Acolyte) on Jul 02, 2017 at 01:40 UTC | |
by mhoang (Acolyte) on Jul 03, 2017 at 03:30 UTC | |
by huck (Prior) on Jul 03, 2017 at 03:46 UTC | |
by mhoang (Acolyte) on Jul 04, 2017 at 05:32 UTC | |
by huck (Prior) on Jul 04, 2017 at 06:01 UTC | |
|