rajeshkumar created the topic: Delete line from string using perl
Questions:
Delete line from string using perl
Delete entry from array based on custom duplicate value.
How to delete lines that match certain pattern
============================
$info = ”
This is Rajesh
This is Ram
This is test
This is Raju
”
Some solutions which i found on net but none of them seems working.
Sol1
if($line =~ /MatchText/){
$line =~ s/ReplaceMe/REPLACED/gi;
}
Sol2
perl -ni -e 'print unless /pattern/' /path/to/filename
Sol3
$ cat /path/to/file | perl -e 'while(<>){ if( /pattern/ ) { $linecount++; } else { print "$_"; } } print STDERR "Deleted $linecount lines.\n"' > /path/to/newfile
Sol4
$_ = "$delete"; #readin file content into standard variable
s/pattern//g; #pattern will get replaced by nothing globally
$delete = $_; #new file content back into old file
Sol5
sed -e '/Bob/d' -e '/Mary/d'
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND