<?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: file manipulation in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839964#M100729</link>
    <description>Hi Nisar:&lt;BR /&gt;&lt;BR /&gt;Perhaps something like this(?):&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/data&lt;BR /&gt;this is line-1 of 3&lt;BR /&gt;this is line-2 of 3&lt;BR /&gt;this is line-3 of 3&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's/.*line-2.*/NEWSTUFF/' /tmp/data&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/data&lt;BR /&gt;this is line-1 of 3&lt;BR /&gt;NEWSTUFF&lt;BR /&gt;this is line-3 of 3&lt;BR /&gt;&lt;BR /&gt;A backup copy of the original file is automatically made as '/tmp/data.old' in this case.  The line matching "line-2" was targeted for replacement in this example.&lt;BR /&gt;&lt;BR /&gt;If you wanted to target line-2 without regard to it's contents, this variation would target and replace it:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e '$.==2 &amp;amp;&amp;amp; s/.*/NEWSTUFF/' /tmp/data&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Wed, 09 Aug 2006 08:14:38 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2006-08-09T08:14:38Z</dc:date>
    <item>
      <title>file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839960#M100725</link>
      <description>Hi All&lt;BR /&gt;&lt;BR /&gt;I want to pick a line from one file and overwite it onto another file in similar place in a SHELL scripting. Any clue please ?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance&lt;BR /&gt;&lt;BR /&gt;Nisar&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Aug 2006 03:01:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839960#M100725</guid>
      <dc:creator>Nisar Ahmad</dc:creator>
      <dc:date>2006-08-09T03:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839961#M100726</link>
      <description>Nisar,&lt;BR /&gt;awk/sed is probably part of the solution, but could you please provide more information or, even better, an example.</description>
      <pubDate>Wed, 09 Aug 2006 03:17:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839961#M100726</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2006-08-09T03:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839962#M100727</link>
      <description>Hi, &lt;BR /&gt;&lt;BR /&gt;You can use perl for file manipulation. &lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Wed, 09 Aug 2006 03:37:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839962#M100727</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-08-09T03:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839963#M100728</link>
      <description>not sure what you want to do. &lt;BR /&gt;Do you want to grab the line from one file and insert it somewhere in the middle of the second file? If so perl would be my choice for that, awk could probably be used aswell.  &lt;BR /&gt;&lt;BR /&gt;If you just want to grab a line and append or overwrite an existing file you can just use grep and &amp;gt;&amp;gt; or &amp;gt; to accomplish that. &lt;BR /&gt;</description>
      <pubDate>Wed, 09 Aug 2006 07:27:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839963#M100728</guid>
      <dc:creator>Marvin Strong</dc:creator>
      <dc:date>2006-08-09T07:27:20Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839964#M100729</link>
      <description>Hi Nisar:&lt;BR /&gt;&lt;BR /&gt;Perhaps something like this(?):&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/data&lt;BR /&gt;this is line-1 of 3&lt;BR /&gt;this is line-2 of 3&lt;BR /&gt;this is line-3 of 3&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's/.*line-2.*/NEWSTUFF/' /tmp/data&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/data&lt;BR /&gt;this is line-1 of 3&lt;BR /&gt;NEWSTUFF&lt;BR /&gt;this is line-3 of 3&lt;BR /&gt;&lt;BR /&gt;A backup copy of the original file is automatically made as '/tmp/data.old' in this case.  The line matching "line-2" was targeted for replacement in this example.&lt;BR /&gt;&lt;BR /&gt;If you wanted to target line-2 without regard to it's contents, this variation would target and replace it:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e '$.==2 &amp;amp;&amp;amp; s/.*/NEWSTUFF/' /tmp/data&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 09 Aug 2006 08:14:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839964#M100729</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-08-09T08:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839965#M100730</link>
      <description>Hi Fergusan&lt;BR /&gt;&lt;BR /&gt;You got me. &lt;BR /&gt;&lt;BR /&gt;Thanks a lot for the great help.</description>
      <pubDate>Wed, 09 Aug 2006 19:18:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839965#M100730</guid>
      <dc:creator>Nisar Ahmad</dc:creator>
      <dc:date>2006-08-09T19:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839966#M100731</link>
      <description>Hi Ferguson&lt;BR /&gt;&lt;BR /&gt;Just want to clear that what is difference betveen two options ?  What -p means ? How about if I want no copy of the file ?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;Nisar</description>
      <pubDate>Wed, 09 Aug 2006 19:37:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839966#M100731</guid>
      <dc:creator>Nisar Ahmad</dc:creator>
      <dc:date>2006-08-09T19:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839967#M100732</link>
      <description>Hi Ferguson&lt;BR /&gt;&lt;BR /&gt;I am having also dificulty how to use a value from a parameter for NEWSTUFF. Like if I read a value from somewhere and assign to a variable say REP then should it work like ( perl -pi -e 's/.*line-3.*/${REP}/' file ) ?&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Nisar</description>
      <pubDate>Wed, 09 Aug 2006 19:51:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839967#M100732</guid>
      <dc:creator>Nisar Ahmad</dc:creator>
      <dc:date>2006-08-09T19:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839968#M100733</link>
      <description>&amp;gt;assign to a variable say REP then should it work like (perl -pi -e 's/.*line-3.*/${REP}/' file) ?&lt;BR /&gt;&lt;BR /&gt;Shell variables aren't expanded within single quotes.  You would have to use double quotes then escape any chars that are special to the shell.  I don't see any above, so using "" would work.</description>
      <pubDate>Wed, 09 Aug 2006 20:25:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839968#M100733</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-08-09T20:25:21Z</dc:date>
    </item>
    <item>
      <title>Re: file manipulation</title>
      <link>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839969#M100734</link>
      <description>Hi (again) Nisar:&lt;BR /&gt;&lt;BR /&gt;If you don't want a backup copy of your file as it exists before the replacements, drop the argument that follows the '-i' switch.  That is, insteadnig of creting a backup copy of '/tmp/data' as '/tmp/data.old' in:&lt;BR /&gt;&lt;BR /&gt;# perl -pi.old -e 's/.*line-2.*/NEWSTUFF/' /tmp/data&lt;BR /&gt;&lt;BR /&gt;...use:&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e 's/.*line-2.*/NEWSTUFF/' /tmp/data&lt;BR /&gt;&lt;BR /&gt;THe '-p' switch creates an implicit loop to read and print file input, like:&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;   ... # do whatever you want here&lt;BR /&gt;  }&lt;BR /&gt;continue {&lt;BR /&gt;    print&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Normally, the output of the print goes to STDOUT.  The addition of the '-i' switch means that the output is automatically directed to the input file (normally) specified on the command line.&lt;BR /&gt;&lt;BR /&gt;You also asked how to make the substitution variable at run time.  Here's one way:&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/data&lt;BR /&gt;this is line-1 of 3&lt;BR /&gt;this is line-2 of 3&lt;BR /&gt;this is line-3 of 3&lt;BR /&gt;&lt;BR /&gt;# perl -pi -e 'BEGIN{$this=shift};s/.*line-2.*/$this/o' YOURSTUFF /tmp/data&lt;BR /&gt;&lt;BR /&gt;# cat /tmp/data&lt;BR /&gt;this is line-1 of 3&lt;BR /&gt;YOURSTUFF&lt;BR /&gt;this is line-3 of 3&lt;BR /&gt;&lt;BR /&gt;...Now our one-line Perl script expects two arguments passed to it.  The first argument is the replacement text and the second argument is the filename on which to operate.&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>Thu, 10 Aug 2006 06:54:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/file-manipulation/m-p/3839969#M100734</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-08-10T06:54:57Z</dc:date>
    </item>
  </channel>
</rss>

