Hi,
Using perl, how can I delete a charecter (specify the position number), in a line which starts with "GETR P" and another line starting with "GET P:=". This needs tro be done for many charecters in a line
Thanks
Vijayalakshmi
Hi,
Using perl, how can I delete a charecter (specify the position number), in a line which starts with "GETR P" and another line starting with "GET P:=". This needs tro be done for many charecters in a line
Thanks
Vijayalakshmi
cat abc.txt | perl -e 'while(<>){
chomp;
my $pos_to_remove = 4; # change this position as per ur req
print substr($_,0,($pos_to_remove-1)).substr($_,$pos_to_remove)."\n";
}'
Alternatively you can use a simple regex as well
cat abc.txt | perl -e 'while(<>){ chomp;
my $pos_to_remove = 3;
s/(.{$pos_to_remove}).(.*)/$1$2/g;
print "$_\n";
}'
HTH,
PL
Input file:
$ cat t
GETR P123456
GET P:=12345
sdflkj sdfkj
Code:
$ cat t.pl
while(<>) {
s/^((GETR P|GET P:=).{3}).(.*)$/\1\3/;
print;
}
Execute it like this:
perl -i t.pl t
After the pattern, the 4th character is deleted. Give appropriate number for your requirement.
$ cat t
GETR P12356
GET P:=1235
sdflkj sdfkj
-------------
Oops, a similar approach as above.. but with the string start is taken care here.
Also, get that variable $pos_to_remove and use here...