{"id":71,"date":"2024-12-06T10:55:25","date_gmt":"2024-12-06T10:55:25","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=71"},"modified":"2024-12-06T10:55:25","modified_gmt":"2024-12-06T10:55:25","slug":"commands-using-grep-or-sed-utility","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2024\/12\/06\/commands-using-grep-or-sed-utility\/","title":{"rendered":"Commands using grep or sed utility"},"content":{"rendered":"\n<p><strong>commands using grep or sed utility<\/strong><\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-6cb2d176b17fa58b866a041ef22ed525\">write grep command for display lines of file F1 that begins with &#8220;The&#8221;<\/p>\n\n\n\n<p>grep &#8216;^The&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-243af895b11248c7ee36d754039698a9\">count total number of blank lines of file F1<\/p>\n\n\n\n<p>grep -c &#8216;^$&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-76774e7198f0b0217f4f64f5d7f309fd\">display the lines of file F1 that do not contain &#8220;Unix&#8221;<\/p>\n\n\n\n<p>grep -v &#8216;Unix&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-6a16376474fab91f8934ebd41b18b78b\">replace all occurrences of &#8216;unix&#8217; with &#8216;linux&#8217; of file F1<\/p>\n\n\n\n<p>sed &#8216;s\/unix\/linux\/g&#8217; F1<\/p>\n\n\n\n<p>sed -i &#8216;s\/unix\/linux\/g&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-6a16376474fab91f8934ebd41b18b78b\">replace all occurrences of &#8216;unix&#8217; with &#8216;linux&#8217; of file F1<\/p>\n\n\n\n<p>sed &#8216;s\/unix\/linux\/g&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-9dcb60d3c722f8499c81fc3e13afa537\">display the lines of file F1 that contain &#8220;VB.net&#8221; and \/ or &#8220;Asp.net&#8221;<\/p>\n\n\n\n<p>grep -E &#8216;VB\\.net|Asp\\.net&#8217; F1<\/p>\n\n\n\n<p>grep -e &#8216;VB\\.net&#8217; -e &#8216;Asp\\.net&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-ecc10494445a9f6216b33bc5a4beed5b\">display lines of file F1 which have exactly 4-characters.<\/p>\n\n\n\n<p>grep -x &#8216;.\\{4\\}&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-a3ab09cce306488669596bf6974f4ad2\">do not display line number 3 to 5 of file F1<\/p>\n\n\n\n<p>sed &#8216;3,5d&#8217; F1<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-44f36507d7d6720f0334d9cc84ede854\">insert blank line after each line of the file F1<\/p>\n\n\n\n<p>sed &#8216;G&#8217; F1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>commands using grep or sed utility write grep command for display lines of file F1 that begins with &#8220;The&#8221; grep &#8216;^The&#8217; F1 count total number of blank lines of file F1 grep -c &#8216;^$&#8217; F1 display the lines of file F1 that do not contain &#8220;Unix&#8221; grep -v &#8216;Unix&#8217; F1 replace all occurrences of &#8216;unix&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":43,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,14],"tags":[17,18,16,15],"class_list":["post-71","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bca","category-unix-shell-programming","tag-grep-example","tag-sed-example","tag-shell-script","tag-unix-shell-programming"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":1,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":72,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions\/72"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/43"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}