{"id":2423,"date":"2017-12-08T10:10:58","date_gmt":"2017-12-08T10:10:58","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2423"},"modified":"2025-02-01T23:08:08","modified_gmt":"2025-02-01T23:08:08","slug":"delete-line-from-string-using-perl","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/delete-line-from-string-using-perl\/","title":{"rendered":"Delete line from string using perl"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: Delete line from string using perl<\/strong><\/p>\n<p>Questions:<br \/>\nDelete line from string using perl<br \/>\nDelete entry from array based on custom duplicate value.<br \/>\nHow to delete lines that match certain pattern<br \/>\n============================<br \/>\n$info = &#8221;<br \/>\nThis is Rajesh<br \/>\nThis is Ram<br \/>\nThis is test<br \/>\nThis is Raju<br \/>\n&#8221;<\/p>\n<p>Some solutions which i found on net but none of them seems working.<\/p>\n<p>Sol1<\/p>\n<p><code>if($line =~ \/MatchText\/){<br \/>\n$line =~ s\/ReplaceMe\/REPLACED\/gi;<br \/>\n}<\/code><\/p>\n<p>Sol2<\/p>\n<p><code>perl -ni -e 'print unless \/pattern\/' \/path\/to\/filename<\/code><\/p>\n<p>Sol3<br \/>\n<code>$ cat \/path\/to\/file | perl -e 'while(<>){ if( \/pattern\/ ) { $linecount++; } else { print \"$_\"; } } print STDERR \"Deleted $linecount lines.\\n\"' > \/path\/to\/newfile<\/code><\/p>\n<p>Sol4<br \/>\n<code>$_ = \"$delete\"; #readin file content into standard variable<br \/>\ns\/pattern\/\/g; #pattern will get replaced by nothing globally<br \/>\n$delete = $_; #new file content back into old file<\/code><\/p>\n<p>Sol5<\/p>\n<p><code>sed -e '\/Bob\/d' -e '\/Mary\/d' <infile >outfile<\/code><\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 = &#8221; This is Rajesh This is Ram This is test This is Raju &#8221; Some solutions which i&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[14],"tags":[175],"class_list":["post-2423","post","type-post","status-publish","format-standard","hentry","category-perl","tag-perl"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2423"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2423\/revisions"}],"predecessor-version":[{"id":2424,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2423\/revisions\/2424"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}