<?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: Need help with scripting mass file edits.. in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054532#M94403</link>
    <description>&lt;!--!*#--&gt;Assuming you wanted to add complete lines after the string you found, you could use sed.  The 3 backslashes are one to quote the next and then one to continue the sed append.&lt;BR /&gt;&lt;BR /&gt;This inserts the text after the string "firstname1".&lt;BR /&gt;&lt;BR /&gt;(Note: TMP in the script below is removed just be tidy.  You don't want to remove your data file.  ;-)&lt;BR /&gt;###########################################################################################&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;TMP=/var/tmp/itrc.in.$$&lt;BR /&gt;&lt;BR /&gt;cat &amp;lt;&lt;EOF&gt; $TMP&lt;BR /&gt;firstname1 lastname1&lt;BR /&gt;firstname2 lastname2&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;sed -e '&lt;BR /&gt;/firstname1/a\&lt;BR /&gt;Cmnd_Alias EPROV_ADMIN_CMDS = /usr/sbin/groupadd, /usr/sbin/groupdel, /usr/sbin/groupmod, \\\&lt;BR /&gt;/usr/bin/last, /usr/bin/listusers, /usr/sbin/logins, \\\&lt;BR /&gt;/usr/sbin/usermod, /usr/sbin/useradd, /usr/sbin/userdel, \\\&lt;BR /&gt;/usr/bin/passwd, /usr/bin/ypmatch, /usr/bin/yppasswd, \\\&lt;BR /&gt;/usr/sbin/ypcat, /usr/bin/login&lt;BR /&gt;' $TMP&lt;BR /&gt;&lt;BR /&gt;rm -f $TMP&lt;BR /&gt;&lt;BR /&gt;If you have this data in a file, you can use the following instead of "a":&lt;BR /&gt;/firstname1/r file-to-insert&lt;/EOF&gt;</description>
    <pubDate>Wed, 15 Aug 2007 06:33:14 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2007-08-15T06:33:14Z</dc:date>
    <item>
      <title>Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054521#M94392</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I am wanting to know a way to shell  (ksh)script-edit a file by having a script that searches for a specific string, and then inputs lines after that specific string.  Please help, as I will be up all night if I can't figure this out.</description>
      <pubDate>Tue, 14 Aug 2007 15:59:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054521#M94392</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-14T15:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054522#M94393</link>
      <description>Hi Patrick:&lt;BR /&gt;&lt;BR /&gt;I am going to assume that you want to preserve the entire contents of the line on which your match occurs, and simply add some number of lines thereafter.&lt;BR /&gt;&lt;BR /&gt;This script will do that for any number of files *and* update them "in-place":&lt;BR /&gt;&lt;BR /&gt;By example, using 'localhost' as a string to be matched (e.g. as with '/etc/hosts'):&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's/(localhost.*)/$1\nnew\nlines\nhere/' file1 file2 file3&lt;BR /&gt;&lt;BR /&gt;The original file will be preserved with an ".old" suffix and the file updated in-place.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 14 Aug 2007 16:46:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054522#M94393</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-14T16:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054523#M94394</link>
      <description>Perhaps I should have stated that I wanted to input lines of text after the string that is being searched out.</description>
      <pubDate>Tue, 14 Aug 2007 17:41:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054523#M94394</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-14T17:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054524#M94395</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; Perhaps I should have stated that I wanted to input lines of text after the string that is being searched out.&lt;BR /&gt;&lt;BR /&gt;OK, and do what with any text that follows the match on the line?&lt;BR /&gt;&lt;BR /&gt;This discards any text on the line on which the pattern matches and inserts new test lines thereafter:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's/(localhost)/$1\nnew\nlines\nhere/' file1 file2 file3 ...&lt;BR /&gt;&lt;BR /&gt;Change the pattern in parentheses to anything you want.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 14 Aug 2007 17:52:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054524#M94395</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-14T17:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054525#M94396</link>
      <description>I would want to keep the text on that line, but I guess a solution would be to let that text be discarded, and re-add it in the replacement text.</description>
      <pubDate>Tue, 14 Aug 2007 18:23:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054525#M94396</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-14T18:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054526#M94397</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I would want to keep the text on that line, but I guess a solution would be to let that text be discarded, and re-add it in the replacement text.&lt;BR /&gt;&lt;BR /&gt;OK, solution-1 retains it.  Solution-2 discards it and this one (solution-3) pushes text that trails the matched pattern to its own line and then inserts the line(s) you specify:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's/(localhost)(.*)/$1\n$2\nnew\nlines\nhere/' file1 file2 file3 ...&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 14 Aug 2007 18:37:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054526#M94397</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-14T18:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054527#M94398</link>
      <description>Nice!  I just tested this out, and it works pretty dang good!!  Thanks so much for your responses.  Solution 3 was the one.</description>
      <pubDate>Tue, 14 Aug 2007 18:58:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054527#M94398</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-14T18:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054528#M94399</link>
      <description>Wait, what if I wanted to enter the followng after the string:&lt;BR /&gt;&lt;BR /&gt;Cmnd_Alias EPROV_ADMIN_CMDS = /usr/sbin/groupadd, /usr/sbin/groupdel, /usr/sbin/groupmod, \&lt;BR /&gt;                              /usr/bin/last, /usr/bin/listusers, /usr/sbin/logins, \&lt;BR /&gt;                              /usr/sbin/usermod, /usr/sbin/useradd, /usr/sbin/userdel, \&lt;BR /&gt;                              /usr/bin/passwd, /usr/bin/ypmatch, /usr/bin/yppasswd, \&lt;BR /&gt;                              /usr/sbin/ypcat, /usr/bin/login&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Is there a way to do this?</description>
      <pubDate>Tue, 14 Aug 2007 19:06:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054528#M94399</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-14T19:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054529#M94400</link>
      <description>I will be up all night if I can't get this figured out.  I just got tasked (last minute) to change the sudoers file on 398 hosts by by tomorrow morning.</description>
      <pubDate>Tue, 14 Aug 2007 19:19:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054529#M94400</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-14T19:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054530#M94401</link>
      <description>I have an aversion to doing someone else's&lt;BR /&gt;job for him when he's getting paid for it&lt;BR /&gt;and I'm not, but if you expect someone else&lt;BR /&gt;to do it for you, you might consider&lt;BR /&gt;precisely and accurately specifying the work&lt;BR /&gt;you want done.  In this case, one way to do&lt;BR /&gt;that might be to show an example of what the&lt;BR /&gt;file would look like before and after the&lt;BR /&gt;change(s) you'd like to make.&lt;BR /&gt;&lt;BR /&gt;When a reply begins, "I am going to assume",&lt;BR /&gt;then _you_ can assume that you didn't specify&lt;BR /&gt;the problem clearly enough.</description>
      <pubDate>Wed, 15 Aug 2007 01:03:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054530#M94401</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2007-08-15T01:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054531#M94402</link>
      <description>1. It's called asking for help, because I don't have the answer.  Because I still have to do the job anyway, I ask those with experience how to do it more efficiently. When a good example is given, I give thanks, take the example, and modify it for what I need to get done, and test it.  I wouldn't say that's doing my work for me.  That's called asking for help!&lt;BR /&gt;&lt;BR /&gt;2. Here's a good example of before and after:&lt;BR /&gt;&lt;BR /&gt;BEFORE:&lt;BR /&gt;# Host alias specification&lt;BR /&gt;&lt;BR /&gt;# User alias specification&lt;BR /&gt;&lt;BR /&gt;# Cmnd alias specification&lt;BR /&gt;&lt;BR /&gt;# User privilege specification&lt;BR /&gt;&lt;BR /&gt;AFTER:&lt;BR /&gt;# Host alias specification&lt;BR /&gt;Host_Alias = hostname&lt;BR /&gt;&lt;BR /&gt;# User alias specification&lt;BR /&gt;User_Alias  ADMINS = someuser&lt;BR /&gt;&lt;BR /&gt;# Cmnd alias specification&lt;BR /&gt;Cmnd_Alias ADMIN_CMDS = /usr/sbin/groupadd, /usr/sbin/groupdel, /usr/sbin/groupmod, /usr/bin/last, /usr/bin/listusers, /usr/sbin/logins,&lt;BR /&gt; /usr/sbin/usermod, /usr/sbin/useradd, /usr/sbin/userdel, /usr/bin/passwd, /usr/bin/ypmatch, /usr/bin/yppasswd,/usr/sbin/ypcat, /usr/bin/login&lt;BR /&gt;&lt;BR /&gt;Cmnd_Alias PROTECTED_CMDS = !/usr/bin/passwd root, !/usr/bin/rm -rf /*, !/usr/bin/chown root&lt;BR /&gt;Cmnd_Alias MISC_CMDS =  /usr/bin/make, /usr/bin/chmod, /usr/bin/awk, /usr/bin/cat,/usr/bin/chown, /usr/bin/cp, /usr/bin/cut, /usr/bin/di&lt;BR /&gt;ff,/usr/bin/grep, /usr/bin/ls, /usr/bin/mv, /usr/bin/rm,/usr/bin/sed, /usr/bin/sleep, /usr/bin/sort, /usr/bin/tail,/bin/echo, /bin/touch, /usr&lt;BR /&gt;/bin/which&lt;BR /&gt;&lt;BR /&gt;# User privilege specification&lt;BR /&gt;IDM_ADMINS  LOCALHOST = MISC_CMDS,ADMIN_CMDS&lt;BR /&gt;&lt;BR /&gt;If there is already text in each section, the text is moved down, and the new text is iserted.&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Aug 2007 06:12:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054531#M94402</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-15T06:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054532#M94403</link>
      <description>&lt;!--!*#--&gt;Assuming you wanted to add complete lines after the string you found, you could use sed.  The 3 backslashes are one to quote the next and then one to continue the sed append.&lt;BR /&gt;&lt;BR /&gt;This inserts the text after the string "firstname1".&lt;BR /&gt;&lt;BR /&gt;(Note: TMP in the script below is removed just be tidy.  You don't want to remove your data file.  ;-)&lt;BR /&gt;###########################################################################################&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;TMP=/var/tmp/itrc.in.$$&lt;BR /&gt;&lt;BR /&gt;cat &amp;lt;&lt;EOF&gt; $TMP&lt;BR /&gt;firstname1 lastname1&lt;BR /&gt;firstname2 lastname2&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;sed -e '&lt;BR /&gt;/firstname1/a\&lt;BR /&gt;Cmnd_Alias EPROV_ADMIN_CMDS = /usr/sbin/groupadd, /usr/sbin/groupdel, /usr/sbin/groupmod, \\\&lt;BR /&gt;/usr/bin/last, /usr/bin/listusers, /usr/sbin/logins, \\\&lt;BR /&gt;/usr/sbin/usermod, /usr/sbin/useradd, /usr/sbin/userdel, \\\&lt;BR /&gt;/usr/bin/passwd, /usr/bin/ypmatch, /usr/bin/yppasswd, \\\&lt;BR /&gt;/usr/sbin/ypcat, /usr/bin/login&lt;BR /&gt;' $TMP&lt;BR /&gt;&lt;BR /&gt;rm -f $TMP&lt;BR /&gt;&lt;BR /&gt;If you have this data in a file, you can use the following instead of "a":&lt;BR /&gt;/firstname1/r file-to-insert&lt;/EOF&gt;</description>
      <pubDate>Wed, 15 Aug 2007 06:33:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054532#M94403</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-08-15T06:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054533#M94404</link>
      <description>&amp;gt;2. Here's a good example of before and after:&lt;BR /&gt;&lt;BR /&gt;You have 4 strings to look for, you need 4 sed "a" functions.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;If there is already text in each section, the text is moved down, and the new text is inserted. &lt;BR /&gt;&lt;BR /&gt;That's what the "a" function does.</description>
      <pubDate>Wed, 15 Aug 2007 06:43:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054533#M94404</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-08-15T06:43:30Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054534#M94405</link>
      <description>Hi (again) Patrick:&lt;BR /&gt;&lt;BR /&gt;Please don't forget to evaluate the answers you received, either:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://forums1.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;https://forums1.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 15 Aug 2007 07:36:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054534#M94405</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-15T07:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054535#M94406</link>
      <description>I won't forget.</description>
      <pubDate>Wed, 15 Aug 2007 07:39:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054535#M94406</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2007-08-15T07:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with scripting mass file edits..</title>
      <link>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054536#M94407</link>
      <description>&lt;!--!*#--&gt;Based on your sample input here is an ex(1) construct you could try:&lt;BR /&gt;&lt;BR /&gt;ex -s infile &amp;lt;&lt;EOF&gt;&lt;/EOF&gt;/^# Cmnd/r !echo "Cmnd_Alias EPROV_ADMIN_CMDS = /usr/bin/last, \\\"&lt;BR /&gt;/^# Cmnd/+r !echo "/usr/sbin/groupmod,/usr/sbin/useradd,/usr/bin/listusers, \\\"&lt;BR /&gt;/^# Cmnd/++r !echo "/usr/bin/ypmatch,/usr/bin/yppasswd,/usr/sbin/ypcat"&lt;BR /&gt;wq&lt;BR /&gt;EOF</description>
      <pubDate>Wed, 15 Aug 2007 10:17:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/need-help-with-scripting-mass-file-edits/m-p/4054536#M94407</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-08-15T10:17:22Z</dc:date>
    </item>
  </channel>
</rss>

