<?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: update several files using sed in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091819#M93373</link>
    <description>&lt;!--!*#--&gt;Hi Chris:&lt;BR /&gt;&lt;BR /&gt;A little Perl can help you update all of your files in one pass, keeping backup copies too:&lt;BR /&gt;&lt;BR /&gt;# cat .filter&lt;BR /&gt;#!/usr/bin/perl -i.old&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;my $insertion = &amp;lt;&amp;lt;'EOF';&lt;BR /&gt;PID=$$&lt;BR /&gt;SCRIPT=$(basename $0)&lt;BR /&gt;echo "$PID \n $SCRIPT" &amp;gt; /tmp/christemp/log&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    print $insertion if $. == 1;&lt;BR /&gt;    print;&lt;BR /&gt;}&lt;BR /&gt;continue {&lt;BR /&gt;    close ARGV if eof;&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...Now simple run:&lt;BR /&gt;&lt;BR /&gt;# ./filter file1 file2 ...&lt;BR /&gt;&lt;BR /&gt;...for as many file names as you require (one or more!).&lt;BR /&gt;&lt;BR /&gt;In the above example, backup copies of file1 and file2 will be named with the ".old" suffix.  The three lines will be added to the top of the original file as requested.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Fri, 08 Feb 2008 18:09:43 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2008-02-08T18:09:43Z</dc:date>
    <item>
      <title>update several files using sed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091816#M93370</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I want to add the following to the top of several files for debugging:&lt;BR /&gt;&lt;BR /&gt;PID=$$&lt;BR /&gt;SCRIPT=$(basename $0)&lt;BR /&gt;echo "$PID \n $SCRIPT" &amp;gt; /tmp/christemp/log&lt;BR /&gt;&lt;BR /&gt;what would be the best sed solution to update these several files all ending in *.cron&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Fri, 08 Feb 2008 17:09:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091816#M93370</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-02-08T17:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: update several files using sed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091817#M93371</link>
      <description>Hi lawrenzo:&lt;BR /&gt;&lt;BR /&gt;Well I think your on the wrong path about sed, which is a line editor and therefore more like vi.  But the way to do this is not difficult at all if you're using a temp file, an input file and an output file along with cat and '&amp;gt;&amp;gt;'.&lt;BR /&gt;&lt;BR /&gt;vi a new file and add in :&lt;BR /&gt;PID=$$&lt;BR /&gt;SCRIPT=$(basename $0)&lt;BR /&gt;echo "$PID \n $SCRIPT" &amp;gt; /tmp/christemp/log&lt;BR /&gt;&lt;BR /&gt;And now cat old file &amp;gt;&amp;gt; to the bottom of the new file.&lt;BR /&gt;&lt;BR /&gt;If you have several files to update then a for loop can be added.&lt;BR /&gt;&lt;BR /&gt;Forget about sed.</description>
      <pubDate>Fri, 08 Feb 2008 17:22:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091817#M93371</guid>
      <dc:creator>Michael Steele_2</dc:creator>
      <dc:date>2008-02-08T17:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: update several files using sed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091818#M93372</link>
      <description>ok thanks - I did think about that but thought there may be a more efficient way of doing this.&lt;BR /&gt;&lt;BR /&gt;I have to insert the data after the first line as these files are scripts so after &lt;BR /&gt;&lt;BR /&gt;#!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;I will have a look &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Feb 2008 17:33:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091818#M93372</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-02-08T17:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: update several files using sed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091819#M93373</link>
      <description>&lt;!--!*#--&gt;Hi Chris:&lt;BR /&gt;&lt;BR /&gt;A little Perl can help you update all of your files in one pass, keeping backup copies too:&lt;BR /&gt;&lt;BR /&gt;# cat .filter&lt;BR /&gt;#!/usr/bin/perl -i.old&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;my $insertion = &amp;lt;&amp;lt;'EOF';&lt;BR /&gt;PID=$$&lt;BR /&gt;SCRIPT=$(basename $0)&lt;BR /&gt;echo "$PID \n $SCRIPT" &amp;gt; /tmp/christemp/log&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    print $insertion if $. == 1;&lt;BR /&gt;    print;&lt;BR /&gt;}&lt;BR /&gt;continue {&lt;BR /&gt;    close ARGV if eof;&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...Now simple run:&lt;BR /&gt;&lt;BR /&gt;# ./filter file1 file2 ...&lt;BR /&gt;&lt;BR /&gt;...for as many file names as you require (one or more!).&lt;BR /&gt;&lt;BR /&gt;In the above example, backup copies of file1 and file2 will be named with the ".old" suffix.  The three lines will be added to the top of the original file as requested.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 08 Feb 2008 18:09:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091819#M93373</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-02-08T18:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: update several files using sed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091820#M93374</link>
      <description>&lt;!--!*#--&gt;Hi (again) Chris:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I have to insert the data after the first line as these files are scripts so after #!/bin/ksh&lt;BR /&gt;&lt;BR /&gt;OK, I should have assumed that.  Use this slightly modified version of what I first provided.  The same rules of engagement apply:&lt;BR /&gt;&lt;BR /&gt;# cat .filter&lt;BR /&gt;#!/usr/bin/perl -i.old&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;&lt;BR /&gt;my $insertion = &amp;lt;&amp;lt;'EOF';&lt;BR /&gt;PID=$$&lt;BR /&gt;SCRIPT=$(basename $0)&lt;BR /&gt;echo "$PID \n $SCRIPT" &amp;gt; /tmp/christemp/log&lt;BR /&gt;EOF&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    if (m{^#!/}) {&lt;BR /&gt;        print $_, $insertion;&lt;BR /&gt;    }&lt;BR /&gt;    else {&lt;BR /&gt;        print $_;&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;continue {&lt;BR /&gt;    close ARGV if eof;&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...now run the script passing the filenames to be filtered.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 08 Feb 2008 20:02:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091820#M93374</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-02-08T20:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: update several files using sed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091821#M93375</link>
      <description>&lt;!--!*#--&gt;If you really want to use sed, it isn't that hard.&lt;BR /&gt;&lt;BR /&gt;for file in *.cron; do&lt;BR /&gt;sed -e '&lt;BR /&gt;1a\&lt;BR /&gt;PID=$$\&lt;BR /&gt;SCRIPT=$(basename $0)\&lt;BR /&gt;echo "$PID \n $SCRIPT" &amp;gt; /tmp/christemp/log&lt;BR /&gt;' $file &amp;gt; $file.new&lt;BR /&gt;if [ -s $file.new ]; then # see if ok?&lt;BR /&gt;  mv $file.new $file&lt;BR /&gt;fi&lt;BR /&gt;done</description>
      <pubDate>Sat, 09 Feb 2008 01:04:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091821#M93375</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-02-09T01:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: update several files using sed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091822#M93376</link>
      <description>thanks all for the help ...&lt;BR /&gt;&lt;BR /&gt;I used James' solution however I can now adopt the other solutions to other tasks.&lt;BR /&gt;&lt;BR /&gt;Chris.</description>
      <pubDate>Mon, 11 Feb 2008 15:09:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/update-several-files-using-sed/m-p/5091822#M93376</guid>
      <dc:creator>lawrenzo_1</dc:creator>
      <dc:date>2008-02-11T15:09:33Z</dc:date>
    </item>
  </channel>
</rss>

