<?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: grep and replace text in a file in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092800#M93443</link>
    <description>ames, Thanks alot, the perl statement worked perfectly...</description>
    <pubDate>Sat, 16 Feb 2008 01:03:36 GMT</pubDate>
    <dc:creator>MikeL_4</dc:creator>
    <dc:date>2008-02-16T01:03:36Z</dc:date>
    <item>
      <title>grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092793#M93436</link>
      <description>I need a way to run a command in a script, that will grep for a parameter, and if fould, replace the entire line where it was found with a new line....&lt;BR /&gt;&lt;BR /&gt;Any ideas on how to accomplish this ?&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Fri, 15 Feb 2008 14:02:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092793#M93436</guid>
      <dc:creator>MikeL_4</dc:creator>
      <dc:date>2008-02-15T14:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092794#M93437</link>
      <description>Either awk or sed is the way to go.&lt;BR /&gt;Give us and example and we will send some ideas.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Feb 2008 14:13:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092794#M93437</guid>
      <dc:creator>Tim Nelson</dc:creator>
      <dc:date>2008-02-15T14:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092795#M93438</link>
      <description>It will become something like:&lt;BR /&gt;awk '/&lt;PATTERN&gt;/ { print "&lt;NEW-FORM&gt;";next}{print}'&lt;/NEW-FORM&gt;&lt;/PATTERN&gt;</description>
      <pubDate>Fri, 15 Feb 2008 14:15:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092795#M93438</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2008-02-15T14:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092796#M93439</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;How about?&lt;BR /&gt;&lt;BR /&gt;# perl -pe 's/(.*trigger.*)/something new/' file&lt;BR /&gt;&lt;BR /&gt;Thus, any line in the file containing the string "trigger" is totally replaced with a line that reads "something new".&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Feb 2008 14:28:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092796#M93439</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-02-15T14:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092797#M93440</link>
      <description>I am checking for PASS_MAX_DAYS, and there are two occurances in the file, one being a comment line which I don't care about, only need to change the actual parameter line..&lt;BR /&gt;&lt;BR /&gt;I've tried these two commands, but the end result is a blank file, which isn't good...&lt;BR /&gt;&lt;BR /&gt;LIN=`/bin/grep -n "PASS_MAX_DAYS" /etc/login.defs | /bin/grep -v "#" | /bin/awk -F : '{print $1}'`&lt;BR /&gt;/bin/awk '{if (NR==${LIN}) $0="PASS_MAX_DAYS     30";print}' /etc/login.defs &amp;gt; /etc/login.defs.NEW&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Feb 2008 19:21:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092797#M93440</guid>
      <dc:creator>MikeL_4</dc:creator>
      <dc:date>2008-02-15T19:21:52Z</dc:date>
    </item>
    <item>
      <title>Re: grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092798#M93441</link>
      <description>A grep of the parameter shows two lines:&lt;BR /&gt;&lt;BR /&gt;12:#    PASS_MAX_DAYS   Maximum number of days a password may be used.&lt;BR /&gt;17:PASS_MAX_DAYS        99999&lt;BR /&gt;&lt;BR /&gt;whish is why I was trying to isolate the 2nd line for the actual line number that needs to be changed....&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Feb 2008 19:32:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092798#M93441</guid>
      <dc:creator>MikeL_4</dc:creator>
      <dc:date>2008-02-15T19:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092799#M93442</link>
      <description>Hi (again) Mike:&lt;BR /&gt;&lt;BR /&gt;You could find the non-commented line matching the parameter you want and change the value that follows it like this:&lt;BR /&gt;&lt;BR /&gt;# perl -pe 'next if /^\s*#/;s/(PASS_MAX_DAYS\s+)(\d+)\b(.*)/${1}1234${3}/' file&lt;BR /&gt;&lt;BR /&gt;This would find lines (any or all) in your file that constain the string:&lt;BR /&gt;&lt;BR /&gt;PASS_MAX_DAYS&lt;BR /&gt;&lt;BR /&gt;...followed by whitespace (\s) and one or more digits (\d+) like:&lt;BR /&gt;&lt;BR /&gt;PASS_MAX_DAYS 10&lt;BR /&gt;&lt;BR /&gt;...or:&lt;BR /&gt;&lt;BR /&gt;PASS_MAX_DAYS 10 #...change to your taste&lt;BR /&gt;&lt;BR /&gt;...and in this example change the '10' to '1234'&lt;BR /&gt;&lt;BR /&gt;If you want to perform this update in-place and retain a backup copy (*.old) of your file, do:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 'next if /^\s*#/;s/(PASS_MAX_DAYS\s+)(\d+)\b(.*)/${1}1234${3}/' file&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 15 Feb 2008 19:54:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092799#M93442</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-02-15T19:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: grep and replace text in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092800#M93443</link>
      <description>ames, Thanks alot, the perl statement worked perfectly...</description>
      <pubDate>Sat, 16 Feb 2008 01:03:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/grep-and-replace-text-in-a-file/m-p/5092800#M93443</guid>
      <dc:creator>MikeL_4</dc:creator>
      <dc:date>2008-02-16T01:03:36Z</dc:date>
    </item>
  </channel>
</rss>

