Yes and Thanks.
I'm trying to remove sections of a file based on an input of values.
Here is a sample of the file I'm trying to "edit"
Code:
section /total/SMS-MT-FSM-DEL-REP045
country: IN
1280363645.979354_PFS_1_1887728354
begin:03
final:56
END
section /total/SMS-MO-FSM001
country: IR
1280105721.484103_PFM_1_1187616097
final:23
END
section /total/SMS-MT-FSM-DEL-REP095
country: IN
1280363645.729309_PFS_1_1084296392
final:43
END
section /total/SMS-MO-FSM001
country: IR
1280105721.484103_PFM_1_1187616097
final:23
END
section /total/SMS-MO-FSM095
country: MO
1280105721.461090_PFM_1_882824215
begin:12
final:89
END
With a list given to me as:
Code:
REP045
REP095
I want to remove the sections of the file related to a list given above.
Desired output:
Code:
section /total/SMS-MO-FSM001
country: IR
1280105721.484103_PFM_1_1187616097
final:23
END
section /total/SMS-MO-FSM095
country: MO
1280105721.461090_PFM_1_882824215
begin:12
final:89
END
Given your explanation this should be able to do it. However, your desired output does not match what you explained.
Code:
#!/usr/bin/perl
#
use strict;
use warnings;
my @list = qw(REP045 REP095);
my %unwanted = map{$_ => 1} @list;
{
local $/="\n\n";
while(<>) {
my ($id) = (split '-', (split '\n')[0])[-1];
print if /$id/ and not $unwanted{$id};
}
}
Code:
section /total/SMS-MO-FSM001
country: IR
1280105721.484103_PFM_1_1187616097
final:23
END
section /total/SMS-MO-FSM001
country: IR
1280105721.484103_PFM_1_1187616097
final:23
END
section /total/SMS-MO-FSM095
country: MO
1280105721.461090_PFM_1_882824215
begin:12
final:89
END
I have to add a variable value to an array, something like this:
......
@my_array_name = $value_of_this_variable;
This doesnt seem to work, any ideas why?
Thanks! (4 Replies)
i have a file called file.txt having the following entries.
2321
2311
2313
4213
i wnat to store these values in a list and i want to iterate the list using loop and store it in another list (1 Reply)
Hi,
Is there an easy way to simulate following Perl code in Bash.
if ( grep {$my_value eq $_} @ARGV ){
print "Do Something\n";
} else {
die "Invalid value";
} (0 Replies)
Hi,
cut -d: -f1,3 /etc/group >rpt.out
I have a doubt in perl. right i am getting list of group user id into rpt.out file. instead i need to store it as an array in perl script. could you please tell me how can i get list of user into an array in perl script..
thanks in advance. (1 Reply)
Hi,
I have 2 arrays:
@names=qw(amith veena chaitra);
@files=qw(file.txt file1.txt file3.txt);
There is one to one relationship between names and files.
There needs to be mapping created between names and files.
The output should be like this:
amith --> file.txt
veena --->... (3 Replies)
Hi,
i want to search and replace array values by using perl
perl -pi -e "s/${d$i]}/${b$j]}" *.xml
i am using while loop for the same. if i excute this,it shows "Substitution replacement not terminated at -e line 1.".
please tell me what's wrong this line (1 Reply)
I have 2 files , i need compare both files field by field, and in the fourth field some value will be interchaged and some value will be **.
ex: file1 john|0.0|4|**:25;JP:50;UY:25
file2 john|0.0|4|JP:50;**:25;UY:25 (4 Replies)