<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: search and delete script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933060#M97350</link>
    <description>Shiv,&lt;BR /&gt;&lt;BR /&gt;Try the below....&lt;BR /&gt;&lt;BR /&gt;awk '{ if ($1=="|abc" || $1=="|bcg") print $2; else print}' file &amp;gt; file.out&lt;BR /&gt;</description>
    <pubDate>Thu, 25 Jan 2007 20:50:46 GMT</pubDate>
    <dc:creator>Haridharan</dc:creator>
    <dc:date>2007-01-25T20:50:46Z</dc:date>
    <item>
      <title>search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933057#M97347</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I want to search and delete using sed some lines from a text files containing some config info.&lt;BR /&gt;&lt;BR /&gt;Say for example, file.txt has content like:-&lt;BR /&gt;&lt;BR /&gt;|abc  |123|&lt;BR /&gt;|bcg  345989|&lt;BR /&gt;|fdk  |8977r89q|&lt;BR /&gt;|jkhssdf  |987q89r89|&lt;BR /&gt;|iuhuihsfdah  |897q89r|&lt;BR /&gt;|sadjfiouoas  |jnasdfjkhasdjk|&lt;BR /&gt;|jkhjkfasfa|  901590fasklfja&lt;BR /&gt;&lt;BR /&gt;I want to search "jkhssdf" and "sadjfiouoas" and delete them and put the content in a file.&lt;BR /&gt;Can someone suggest a quick shell or perl script ?&lt;BR /&gt;&lt;BR /&gt;Appreciate your help.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Shiv</description>
      <pubDate>Thu, 25 Jan 2007 13:39:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933057#M97347</guid>
      <dc:creator>Shivkumar</dc:creator>
      <dc:date>2007-01-25T13:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933058#M97348</link>
      <description>Hi Shiv:&lt;BR /&gt;&lt;BR /&gt;This will find the tokens you indicated and funnel those matching lines into the STDERR stream.  The non-matching lines will be directed to STDOUT:&lt;BR /&gt;&lt;BR /&gt;#  perl -ne 'if (m{^\|jkhssdf|^\|sadjfiouoas}) {print STDERR} else {print}' file &amp;gt; file.1 2&amp;gt; file.2&lt;BR /&gt;&lt;BR /&gt;...Thus the original file ("file") is left intact and "file.1" contains the non-matching lines; "file.2" contains the matching lines.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 25 Jan 2007 13:58:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933058#M97348</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-01-25T13:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933059#M97349</link>
      <description>&lt;!--!*#--&gt;Try the shell script below:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;ex -s file &amp;lt;&amp;lt;-EOF&lt;BR /&gt;  /^|jkhssdf/w file.out | /^|jkhssdf/d&lt;BR /&gt;  /^|sadjfiouoas/w &amp;gt;&amp;gt; file.out | /^|sadjfiouoas/d&lt;BR /&gt;wq&lt;BR /&gt;EOF</description>
      <pubDate>Thu, 25 Jan 2007 14:18:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933059#M97349</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-01-25T14:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933060#M97350</link>
      <description>Shiv,&lt;BR /&gt;&lt;BR /&gt;Try the below....&lt;BR /&gt;&lt;BR /&gt;awk '{ if ($1=="|abc" || $1=="|bcg") print $2; else print}' file &amp;gt; file.out&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Jan 2007 20:50:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933060#M97350</guid>
      <dc:creator>Haridharan</dc:creator>
      <dc:date>2007-01-25T20:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933061#M97351</link>
      <description>If you don't mind two passes over your data file you can just use grep:&lt;BR /&gt;&lt;BR /&gt;$ grep -e jkhssdf -e sadjfiouoas file.txt &amp;gt; file-extract.txt&lt;BR /&gt;$ grep -v -e jkhssdf -e sadjfiouoas file.txt &amp;gt; new_file.txt</description>
      <pubDate>Thu, 25 Jan 2007 21:28:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933061#M97351</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-01-25T21:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933062#M97352</link>
      <description>Hi Shiv&lt;BR /&gt;&lt;BR /&gt;You can do this in simple vi.&lt;BR /&gt;Open your config file in vi editor&lt;BR /&gt;press "Esc"&lt;BR /&gt;you will be given with the edit prompt :&lt;BR /&gt;The type the below to replace jkhssdf&lt;BR /&gt;%s/jkhssdf//g&lt;BR /&gt;and to replace the sadjfiouoas&lt;BR /&gt;%s/sadjfiouoas//g&lt;BR /&gt;g stands to do the change globally in the whole file.&lt;BR /&gt;Be aware the change wil be made in the current file. If you want to have old file also for reference take a copy of the same before doing the change.&lt;BR /&gt;sed would be the best option to find and replace and keep the original intact&lt;BR /&gt;sed -e "s/jkhssdf//" -e "s/sadjfiouoas//" original_file_name &amp;gt;new_file_name&lt;BR /&gt;&lt;BR /&gt;TQ&lt;BR /&gt;Perumal</description>
      <pubDate>Fri, 26 Jan 2007 01:03:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933062#M97352</guid>
      <dc:creator>perumal_2</dc:creator>
      <dc:date>2007-01-26T01:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933063#M97353</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I assume you will specify your string to delete being a complete content of a field.&lt;BR /&gt;I that is right, I recommend NOT using grep for this filtering, as Dennis suggested.&lt;BR /&gt;Having data&lt;BR /&gt;|abc |123|&lt;BR /&gt;|bcg 345989|&lt;BR /&gt;|fdabck |8977r89q|&lt;BR /&gt;&lt;BR /&gt;and trying to drop 'abc'&lt;BR /&gt;will lead to a deletion of the last line as well.&lt;BR /&gt;&lt;BR /&gt;Question: I see '|' as delimiter, and your content contains sometimes space as well.&lt;BR /&gt;Does it have any meaning - so you see it as a part of the content as well - or is it just a formatting character which could be dropped?&lt;BR /&gt;The procedure we have to use to detect - and remove - a field depending on user supplied strings will depend heavily on that.&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 26 Jan 2007 12:42:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933063#M97353</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-01-26T12:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933064#M97354</link>
      <description>Yes. pipe and space both are delimiter here.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Shiv</description>
      <pubDate>Fri, 26 Jan 2007 12:52:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933064#M97354</guid>
      <dc:creator>Shivkumar</dc:creator>
      <dc:date>2007-01-26T12:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933065#M97355</link>
      <description>&lt;!--!*#--&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;preface:&lt;BR /&gt;- the first field is always empty (before the first delimiter), so I deal with fieldnumbers &amp;gt;1 only.&lt;BR /&gt;- a space is a field delimiter (and not just to ignore), a string&lt;BR /&gt;|a |b|&lt;BR /&gt;has five fields: EMPTY,a,EPMTY,b,EMPTY&lt;BR /&gt;&lt;BR /&gt;case 1) The search string has to be looked up in the second field only&lt;BR /&gt;awk -F'[ |]' -v sea='str1 str2 ...' 'BEGIN {&lt;BR /&gt;s=split(sea,ars," ") }&lt;BR /&gt;{ for(j=1;j&amp;lt;=s;j++) if($2==ars[j]) next }&lt;BR /&gt;{print}' inputfile&lt;BR /&gt;&lt;BR /&gt;case 2) If you want to lookup in all fields, enclose the 2nd line with an additional loop, e.g.&lt;BR /&gt;{ for(i=NF;i&amp;gt;1;i--) if($i) { for(j=1;j&amp;lt;=s;j++) if($2==ars[j]) next } }&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Fri, 26 Jan 2007 13:33:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933065#M97355</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-01-26T13:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933066#M97356</link>
      <description>Hi SHiv:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Yes. pipe and space both are delimiter here.&lt;BR /&gt;&lt;BR /&gt;In that case, I might use:&lt;BR /&gt;&lt;BR /&gt;# perl -ne 'if (m{([\s|])(jkhssdf|sadjfiouoas)([\s|])}) {print STDERR} else {print}' file &amp;gt; file.1 2&amp;gt; file.2&lt;BR /&gt;&lt;BR /&gt;The '\s' is any whitespace character.&lt;BR /&gt;&lt;BR /&gt;Now, if you want this generalized a bit, so that you could *pass* the argument(s) for which you want to search and delele, do this:&lt;BR /&gt;&lt;BR /&gt;# perl -ne 'BEGIN{$re=shift};if (m{([\s|])($re)([\s|])}) {print STDERR} else {print}' jkhssdf\|sadjfiouoas file &amp;gt; file.1 2&amp;gt; file.2&lt;BR /&gt;&lt;BR /&gt;Notice that now you pass the pattern to be found and then the name of the input file.&lt;BR /&gt;&lt;BR /&gt;Notice too, that I escaped the "|" in the pattern so that the shell would not interpret it.  The notation "a|b" means match "a" OR "b".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 26 Jan 2007 14:38:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933066#M97356</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-01-26T14:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933067#M97357</link>
      <description>&amp;gt;Peter: I recommend NOT using grep for this filtering&lt;BR /&gt;&lt;BR /&gt;There is nothing wrong with grep and in fact that issue will appear in awk, sed or perl.  (JRF fixed his.)&lt;BR /&gt;&lt;BR /&gt;You are correct that in all cases you need to add the field delimiters to make sure you don't pick up substrings.&lt;BR /&gt;&lt;BR /&gt;So a fix to my example would be:&lt;BR /&gt;$ grep -e "|jkhssdf " -e "|sadjfiouoas "&lt;BR /&gt;&lt;BR /&gt;Though a grep -w may work with my original example.</description>
      <pubDate>Fri, 26 Jan 2007 16:50:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933067#M97357</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-01-26T16:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933068#M97358</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;remarks for Dennis:&lt;BR /&gt;I told, I recommend NOT using grep == when the whole field content is specified for filtering ==&lt;BR /&gt;In other cases a grep is prefectly okay.&lt;BR /&gt;&lt;BR /&gt;In my awk solution, I did use a compare&lt;BR /&gt;... $2==ars[j] ...&lt;BR /&gt;an NOT a match operator: the latter would in deed nothing change to a grep solution.&lt;BR /&gt;&lt;BR /&gt;The option '-w' is not available at HP-UX's grep, IMHO.&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Sat, 27 Jan 2007 09:10:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933068#M97358</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2007-01-27T09:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: search and delete script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933069#M97359</link>
      <description>&amp;gt;recommend NOT using grep == when the whole field content is specified for filtering&lt;BR /&gt;&lt;BR /&gt;This will work if you anchor it with the delimiter.  (If you remember to do so, as you correctly pointed out.)&lt;BR /&gt;&lt;BR /&gt;&amp;gt;The option '-w' is not available at HP-UX's grep&lt;BR /&gt;&lt;BR /&gt;It is there in 11.11.</description>
      <pubDate>Sat, 27 Jan 2007 09:17:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/search-and-delete-script/m-p/3933069#M97359</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-01-27T09:17:33Z</dc:date>
    </item>
  </channel>
</rss>

