<?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: Replace two words in a file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850047#M825784</link>
    <description>Mine is of course the shortest and simplest ... but wrong :( [ forgot the -l ]&lt;BR /&gt;&lt;BR /&gt;# grep -r -l 'Imp mode' . | xargs perl -pi -e's/\bImp mode\b/test mode/g'</description>
    <pubDate>Fri, 22 Nov 2002 12:56:59 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2002-11-22T12:56:59Z</dc:date>
    <item>
      <title>Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850033#M825770</link>
      <description>&lt;BR /&gt;Hi guys, this should be nice and easy :)&lt;BR /&gt;&lt;BR /&gt;I'm not the best at scripting and can't make sense of the man pages. I need to change line two of a 100+ files in a directory.&lt;BR /&gt;&lt;BR /&gt;line two currently reads: GROUP "Imp mode"&lt;BR /&gt;&lt;BR /&gt;I want to change this to: GROUP "test mode"&lt;BR /&gt;&lt;BR /&gt;pseudo:&lt;BR /&gt;&lt;BR /&gt;for each file in directory do&lt;BR /&gt;replace line two field two with "test mode" (including quotes)&lt;BR /&gt;done. &lt;BR /&gt;&lt;BR /&gt;I started reading man pages for awk but then gave up very quickly. Started reading through sed but then thought of this forum....&lt;BR /&gt;&lt;BR /&gt;Would appreciate any help.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Mohammed U. Ali.</description>
      <pubDate>Fri, 22 Nov 2002 10:14:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850033#M825770</guid>
      <dc:creator>Mohammed Usman Ali</dc:creator>
      <dc:date>2002-11-22T10:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850034#M825771</link>
      <description>Mohammed&lt;BR /&gt;&lt;BR /&gt;for i in `find / -type f`&lt;BR /&gt;do&lt;BR /&gt;file $i | grep -q text&lt;BR /&gt;if [ $? -eq 0 ];then&lt;BR /&gt;        cat $i | sed s'/imp mode/test mode/'&amp;gt;$i.out&lt;BR /&gt;        mv $i.out $i&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Gidoen&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Nov 2002 10:23:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850034#M825771</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2002-11-22T10:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850035#M825772</link>
      <description>Mohammed&lt;BR /&gt;&lt;BR /&gt;the same with awk: &lt;BR /&gt;&lt;BR /&gt;for i in `find / -type f` &lt;BR /&gt;do &lt;BR /&gt; file $i | grep -q text &lt;BR /&gt; if [ $? -eq 0 ];then &lt;BR /&gt; awk &amp;lt;$i '&lt;BR /&gt;    NR == 2 { sub("imp  mode", "test mode" }&lt;BR /&gt;    { print }' &amp;gt;$i.out &lt;BR /&gt;mv $i.out $i &lt;BR /&gt;fi &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Gidoen &lt;BR /&gt;</description>
      <pubDate>Fri, 22 Nov 2002 10:29:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850035#M825772</guid>
      <dc:creator>Klaus Crusius</dc:creator>
      <dc:date>2002-11-22T10:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850036#M825773</link>
      <description>Thanks guys,&lt;BR /&gt;&lt;BR /&gt;Fortunately I can make sense of the syntax :)&lt;BR /&gt;&lt;BR /&gt;I'm still trying to understand why you used '-type f' in your find syntax... what does f stand for? (file?)&lt;BR /&gt;&lt;BR /&gt;I've found that using 'find .' would be enough?&lt;BR /&gt;&lt;BR /&gt;Kind regards&lt;BR /&gt;&lt;BR /&gt;Mohammed.</description>
      <pubDate>Fri, 22 Nov 2002 11:38:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850036#M825773</guid>
      <dc:creator>Mohammed Usman Ali</dc:creator>
      <dc:date>2002-11-22T11:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850037#M825774</link>
      <description>Mohammed,&lt;BR /&gt;&lt;BR /&gt;find . ( or / = location) -type f (= regular file)&lt;BR /&gt;&lt;BR /&gt;file $i = to find out if the file is text or binary.&lt;BR /&gt;&lt;BR /&gt;Gideon&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Nov 2002 11:43:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850037#M825774</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2002-11-22T11:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850038#M825775</link>
      <description>Thanks,&lt;BR /&gt;&lt;BR /&gt;I've just realised that not all the files have line GROUP "Imp mode" some have GROUP "something else"&lt;BR /&gt;&lt;BR /&gt;Could I just script it so that it replaces whatever is in the quotes?&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Mohammed.</description>
      <pubDate>Fri, 22 Nov 2002 11:48:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850038#M825775</guid>
      <dc:creator>Mohammed Usman Ali</dc:creator>
      <dc:date>2002-11-22T11:48:59Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850039#M825776</link>
      <description>Mohammed:&lt;BR /&gt;&lt;BR /&gt;for i in `find / -type f` &lt;BR /&gt;do &lt;BR /&gt;file $i | grep -q text &lt;BR /&gt;if [ $? -eq 0 ];then &lt;BR /&gt;cat $i | sed s'/"...................................."/"test mode"/'&amp;gt;$i.out &lt;BR /&gt;mv $i.out $i &lt;BR /&gt;fi &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;a . = any character.&lt;BR /&gt;&lt;BR /&gt;Gideon&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Nov 2002 11:56:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850039#M825776</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2002-11-22T11:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850040#M825777</link>
      <description>&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;The problem with that is that I have other lines in the file that have text in quotes. So it will affect them also. &lt;BR /&gt;&lt;BR /&gt;Could I not be specific i.e. specify line 2 field 2 or the word after GROUP?&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Mohammed.</description>
      <pubDate>Fri, 22 Nov 2002 12:08:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850040#M825777</guid>
      <dc:creator>Mohammed Usman Ali</dc:creator>
      <dc:date>2002-11-22T12:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850041#M825778</link>
      <description>using GNU grep and perl (with in-file replace):&lt;BR /&gt;&lt;BR /&gt;# grep -r 'Imp mode' . | xargs perl -pi -e's/\bImp mode\b/test mode/g'</description>
      <pubDate>Fri, 22 Nov 2002 12:09:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850041#M825778</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-11-22T12:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850042#M825779</link>
      <description>Mohammed: &lt;BR /&gt;&lt;BR /&gt;for i in `find / -type f` &lt;BR /&gt;do &lt;BR /&gt;file $i | grep -q text &lt;BR /&gt;if [ $? -eq 0 ];then &lt;BR /&gt;cat $i | sed s'/GROUP "...................................."/GROUP "test mode"/'&amp;gt;$i.out &lt;BR /&gt;mv $i.out $i &lt;BR /&gt;fi &lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;a . = any character. &lt;BR /&gt;&lt;BR /&gt;Gideon &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Nov 2002 12:11:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850042#M825779</guid>
      <dc:creator>G. Vrijhoeven</dc:creator>
      <dc:date>2002-11-22T12:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850043#M825780</link>
      <description>Here's a basic script to edit each file in the current directory 'in situ' with ex...&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;find . -type f | {&lt;BR /&gt;while read F&lt;BR /&gt;do&lt;BR /&gt; ex $F &amp;lt;&amp;lt; EOD&lt;BR /&gt;/^GROUP "&lt;BR /&gt;s/".*/"test mode"&lt;BR /&gt;wq&lt;BR /&gt;EOD&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;It changes the first record starting 'GROUP "' to 'GROUP "test mode".&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;John/Jimmy</description>
      <pubDate>Fri, 22 Nov 2002 12:14:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850043#M825780</guid>
      <dc:creator>John Palmer</dc:creator>
      <dc:date>2002-11-22T12:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850044#M825781</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Much more simplier ...&lt;BR /&gt;&lt;BR /&gt;for i in $(find / -type f -exec grep -q "GROUP" {} \; )&lt;BR /&gt;do&lt;BR /&gt;  awk '{&lt;BR /&gt;    if ($2 == "GROUP")&lt;BR /&gt;      print "GROUP \"test mode\""&lt;BR /&gt;    else&lt;BR /&gt;      print' $i &amp;gt; $i.out&lt;BR /&gt;  mv $i.out $i &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;or with sed :&lt;BR /&gt;&lt;BR /&gt;for i in $(find / -type f -exec grep -q "GROUP" {} \; )&lt;BR /&gt;do&lt;BR /&gt;  sed 's/^GROUP ".*"$/GROUP "test mode"/' $i &amp;gt; $i.out&lt;BR /&gt;  mv $i.out $i &lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Fri, 22 Nov 2002 12:15:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850044#M825781</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2002-11-22T12:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850045#M825782</link>
      <description>Hi.&lt;BR /&gt;&lt;BR /&gt;I think that&lt;BR /&gt;sed s/GROUP *\"[^\"]*\"/GROUP \"test mode\"/&lt;BR /&gt;would be much more precise and accurate.&lt;BR /&gt;&lt;BR /&gt;PS.: Looks complicated, but:&lt;BR /&gt;* = repeat the previous expression many times (includeing zero times)&lt;BR /&gt;[^x] = character that is not 'x'&lt;BR /&gt;quotes should be following backslash to ommit their special meaning.&lt;BR /&gt;&lt;BR /&gt;In previous exaples you change every string in quotes.&lt;BR /&gt;In this you change only strings in quotes that are following 'GROUP' (and any number of spaces).&lt;BR /&gt;&lt;BR /&gt;Good luck&lt;BR /&gt;&lt;BR /&gt;Adam&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Nov 2002 12:26:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850045#M825782</guid>
      <dc:creator>Adam J Markiewicz</dc:creator>
      <dc:date>2002-11-22T12:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850046#M825783</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I am very sorry ... When I reread this post it's possible to read that my solutions are simplier than others ... It's really not the case. I just wanted to write that the second form of the problem was simplier than the first form ... But with posting delays ...&lt;BR /&gt;&lt;BR /&gt;Regards.</description>
      <pubDate>Fri, 22 Nov 2002 12:30:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850046#M825783</guid>
      <dc:creator>Jean-Louis Phelix</dc:creator>
      <dc:date>2002-11-22T12:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850047#M825784</link>
      <description>Mine is of course the shortest and simplest ... but wrong :( [ forgot the -l ]&lt;BR /&gt;&lt;BR /&gt;# grep -r -l 'Imp mode' . | xargs perl -pi -e's/\bImp mode\b/test mode/g'</description>
      <pubDate>Fri, 22 Nov 2002 12:56:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850047#M825784</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2002-11-22T12:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Replace two words in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850048#M825785</link>
      <description>Thanks for the overwhelming response guys.&lt;BR /&gt;&lt;BR /&gt;I went with Jean-Louis's sed solution in the end because it was easiest for me to understand. However, I've made note of the other methods and have given you the points you deserve :)&lt;BR /&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;&lt;BR /&gt;Mohammed.</description>
      <pubDate>Fri, 22 Nov 2002 14:10:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-two-words-in-a-file/m-p/2850048#M825785</guid>
      <dc:creator>Mohammed Usman Ali</dc:creator>
      <dc:date>2002-11-22T14:10:11Z</dc:date>
    </item>
  </channel>
</rss>

