<?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 whole line using sed or awk in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849426#M395022</link>
    <description>&lt;BR /&gt;A nice simple approach:&lt;BR /&gt;&lt;BR /&gt;Say the string you are looking for is STRING_TO_BE_REPLACED.&lt;BR /&gt;And the line you want to insert is LINE_TO_REPLACE_WITH.&lt;BR /&gt;The input file is 'file', the output file is 'new_file':&lt;BR /&gt;&lt;BR /&gt;cat file | sed 's/^.*STRING_TO_BE_REPLACED.*$/LINE_TO_REPLACE_WITH/' &amp;gt;new_file&lt;BR /&gt;&lt;BR /&gt;The ^ is a start of line anchor, the '.*' is a wildcard, the $ is a end of line anchor.&lt;BR /&gt;&lt;BR /&gt;Personally I think this looks a lot cleaner than most of the other ways to do this I've seen here.&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Fri, 01 Aug 2003 12:53:09 GMT</pubDate>
    <dc:creator>Stephen Day</dc:creator>
    <dc:date>2003-08-01T12:53:09Z</dc:date>
    <item>
      <title>Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849415#M395011</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;I need to replace an entire line that contains a certain string with another line. &lt;BR /&gt;&lt;BR /&gt;Does anyone know how I could do this? If awk or sed are not the best tools to do this I am open to suggestions. &lt;BR /&gt;&lt;BR /&gt;Sorry if I am duplicating, but I have been reading man pages and trawling the posts on this website for the last 2 hours.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Ross&lt;BR /&gt;</description>
      <pubDate>Thu, 31 Jul 2003 05:06:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849415#M395011</guid>
      <dc:creator>Ross W</dc:creator>
      <dc:date>2003-07-31T05:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849416#M395012</link>
      <description>Is this what you after?&lt;BR /&gt;&lt;BR /&gt;$ sed 's /string/new string/g' old_filename &amp;gt;new_filename</description>
      <pubDate>Thu, 31 Jul 2003 05:15:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849416#M395012</guid>
      <dc:creator>Michael Tully</dc:creator>
      <dc:date>2003-07-31T05:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849417#M395013</link>
      <description>Hi Ross&lt;BR /&gt;&lt;BR /&gt;Don't know if this is what you're after:&lt;BR /&gt;&lt;BR /&gt;sed 's/&lt;OLD string=""&gt;/&lt;NEW string=""&gt;/' &lt;FILENAME&gt; &amp;gt; /tmp/newfile.&lt;BR /&gt;&lt;BR /&gt;Then mv the newfile over the old.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Con&lt;/FILENAME&gt;&lt;/NEW&gt;&lt;/OLD&gt;</description>
      <pubDate>Thu, 31 Jul 2003 05:18:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849417#M395013</guid>
      <dc:creator>Con O'Kelly</dc:creator>
      <dc:date>2003-07-31T05:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849418#M395014</link>
      <description>sed 's/string/new string/g' file &amp;gt; new_file</description>
      <pubDate>Thu, 31 Jul 2003 05:25:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849418#M395014</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2003-07-31T05:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849419#M395015</link>
      <description>Very similar, but I need the whole line replaced, not just the search string text. &lt;BR /&gt;&lt;BR /&gt;For Example:&lt;BR /&gt;I have a file which sometimes contains this text. &lt;BR /&gt;&lt;BR /&gt;  quick brown fox&lt;BR /&gt;&lt;BR /&gt;and sometimes contains&lt;BR /&gt;&lt;BR /&gt;  slow brown fox&lt;BR /&gt;&lt;BR /&gt;I want to search for "brown" and then replace the entire line. &lt;BR /&gt;&lt;BR /&gt;Any ideas? &lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Ross</description>
      <pubDate>Thu, 31 Jul 2003 05:29:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849419#M395015</guid>
      <dc:creator>Ross W</dc:creator>
      <dc:date>2003-07-31T05:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849420#M395016</link>
      <description>&lt;P&gt;Have a look at this thread, it may helps:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.hpe.com/t5/System-Administration/bd-p/itrc-156#.WNOdhE27odk" target="_blank"&gt;https://community.hpe.com/t5/System-Administration/bd-p/itrc-156#.WNOdhE27odk&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2017 10:06:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849420#M395016</guid>
      <dc:creator>twang</dc:creator>
      <dc:date>2017-03-23T10:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849421#M395017</link>
      <description>Hi,&lt;BR /&gt;the slow approach:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read LINE&lt;BR /&gt;do&lt;BR /&gt;        echo "$LINE" | grep -iq brown&lt;BR /&gt;        if [ "$?" = "0" ]&lt;BR /&gt;        then&lt;BR /&gt;                echo "Replaced line"&lt;BR /&gt;        else&lt;BR /&gt;                echo "$LINE"&lt;BR /&gt;        fi&lt;BR /&gt;done &amp;lt;$1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.&lt;BR /&gt;</description>
      <pubDate>Thu, 31 Jul 2003 05:56:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849421#M395017</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2003-07-31T05:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849422#M395018</link>
      <description>awk '{x=0;for(i=1;i&amp;lt;=NF;i++){if($i ~ /brown/) print "new line/string";x=1;break}};if (x==0) print $0}' your_file &amp;gt; new_file</description>
      <pubDate>Fri, 01 Aug 2003 06:33:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849422#M395018</guid>
      <dc:creator>Ionut Grigorescu_2</dc:creator>
      <dc:date>2003-08-01T06:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849423#M395019</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;Script on perl:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;open (FD, "SRC_FILENAME");&lt;BR /&gt;open (FDN, "&amp;gt;TRGET_FILENAME");&lt;BR /&gt;&lt;BR /&gt;foreach (&lt;FD&gt;)&lt;BR /&gt;{&lt;BR /&gt;  if (/STRING_FOR_REPLACE/)&lt;BR /&gt;  {&lt;BR /&gt;    print FDN "NEW_STRING_LINE";&lt;BR /&gt;  }&lt;BR /&gt;  else&lt;BR /&gt;  {&lt;BR /&gt;    print FDN "$_";&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;close (FDN);&lt;BR /&gt;close (FD);&lt;BR /&gt;#END&lt;BR /&gt;&lt;BR /&gt;Caesar&lt;/FD&gt;</description>
      <pubDate>Fri, 01 Aug 2003 08:41:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849423#M395019</guid>
      <dc:creator>Caesar_3</dc:creator>
      <dc:date>2003-08-01T08:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849424#M395020</link>
      <description>awk ' toupper($0) ~ /BROWN/ {print "new row"}'&lt;BR /&gt;&lt;BR /&gt;I should think this would do what I expect You to ask for.&lt;BR /&gt;&lt;BR /&gt;If brown exist anyware in the input row, case independent, the whole input line is replaced by a new standard row.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Aug 2003 09:00:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849424#M395020</guid>
      <dc:creator>Rolf Modin</dc:creator>
      <dc:date>2003-08-01T09:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849425#M395021</link>
      <description>Hm...&lt;BR /&gt;&lt;BR /&gt;awk ' toupper($0) ~ / BROWN[\.,!? ]/ {print "new row"}' input &amp;gt; output&lt;BR /&gt;&lt;BR /&gt;This version acts only when 'brown' is used as a sepatate word, and not for instnace as 'brownies'. It accepts ".", ",", "!", "?" and " " as the character after 'brown'.&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;</description>
      <pubDate>Fri, 01 Aug 2003 09:18:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849425#M395021</guid>
      <dc:creator>Rolf Modin</dc:creator>
      <dc:date>2003-08-01T09:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849426#M395022</link>
      <description>&lt;BR /&gt;A nice simple approach:&lt;BR /&gt;&lt;BR /&gt;Say the string you are looking for is STRING_TO_BE_REPLACED.&lt;BR /&gt;And the line you want to insert is LINE_TO_REPLACE_WITH.&lt;BR /&gt;The input file is 'file', the output file is 'new_file':&lt;BR /&gt;&lt;BR /&gt;cat file | sed 's/^.*STRING_TO_BE_REPLACED.*$/LINE_TO_REPLACE_WITH/' &amp;gt;new_file&lt;BR /&gt;&lt;BR /&gt;The ^ is a start of line anchor, the '.*' is a wildcard, the $ is a end of line anchor.&lt;BR /&gt;&lt;BR /&gt;Personally I think this looks a lot cleaner than most of the other ways to do this I've seen here.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Aug 2003 12:53:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849426#M395022</guid>
      <dc:creator>Stephen Day</dc:creator>
      <dc:date>2003-08-01T12:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849427#M395023</link>
      <description>shame on me!&lt;BR /&gt;&lt;BR /&gt;This is how it works well:&lt;BR /&gt;&lt;BR /&gt;awk '{if(toupper($0) ~ / BROWN[;\.,!? ]/) {print "new row"} else {print $0}}' input&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The text "brown" will trigger a complete different standard line to be printed instead of the line "brown" is found in. But the line will only be replaces if "brown" begins with a space, and if the character after "brown" is one of ";.,!?" or space. The check will ignore case.&lt;BR /&gt;&lt;BR /&gt;If it looks like "[" or "]" that should be replaces with sqare brackets instead.&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Feb 2005 10:48:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849427#M395023</guid>
      <dc:creator>Rolf Modin</dc:creator>
      <dc:date>2005-02-10T10:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849428#M395024</link>
      <description>shame on me!&lt;BR /&gt;&lt;BR /&gt;This is how it works well:&lt;BR /&gt;&lt;BR /&gt;awk '{if(toupper($0) ~ / BROWN[;\.,!? ]/) {print "new row"} else {print $0}}' input&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The text "brown" will trigger a complete different standard line to be printed instead of the line "brown" is found in. But the line will only be replaced if "brown" begins with a space, and if the character after "brown" is one of ";.,!?" or space. The check will ignore case.&lt;BR /&gt;&lt;BR /&gt;If it looks like "[" or "]" that should be replaces with sqare brackets instead.&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Feb 2005 10:48:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849428#M395024</guid>
      <dc:creator>Rolf Modin</dc:creator>
      <dc:date>2005-02-10T10:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849429#M395025</link>
      <description>You could put it in a script if you have to do this more than once using a couple of different variables i.e;&lt;BR /&gt;&lt;BR /&gt;# file1 contains line to insert&lt;BR /&gt;REPLN=`cat file1`&lt;BR /&gt;# or set the variable with the line to be #inserted&lt;BR /&gt;REPLN="dumb ol fox"&lt;BR /&gt;&lt;BR /&gt;sed "s/^.*$2.*$/$REPLN/ $1 &amp;gt; $1.a&lt;BR /&gt;mv $1.a $1  # overwrite the original file&lt;BR /&gt;&lt;BR /&gt;run it &lt;BR /&gt;swtchln.sh myfile brown&lt;BR /&gt;&lt;BR /&gt;course there's lots of mods you can make to this, but you get the gist of it.&lt;BR /&gt;</description>
      <pubDate>Thu, 10 Feb 2005 13:26:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849429#M395025</guid>
      <dc:creator>Robert Salter</dc:creator>
      <dc:date>2005-02-10T13:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Replace whole line using sed or awk</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849430#M395026</link>
      <description>close</description>
      <pubDate>Mon, 02 Feb 2009 01:22:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/replace-whole-line-using-sed-or-awk/m-p/4849430#M395026</guid>
      <dc:creator>Ross W</dc:creator>
      <dc:date>2009-02-02T01:22:41Z</dc:date>
    </item>
  </channel>
</rss>

