<?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: change a line in a file in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707243#M103430</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;in this cases I generate ed-commands to do this.&lt;BR /&gt;Note1: Backup the files before you try!&lt;BR /&gt;Note2: use your appropriate method of getting the filenames&lt;BR /&gt;Note3: better tighten the pattern used for the global match (2nd print statement)&lt;BR /&gt;&lt;BR /&gt;oldserver=XXX&lt;BR /&gt;newseerver=YYY&lt;BR /&gt;for f in $(fgrep -l $oldserver *.html)&lt;BR /&gt;do&lt;BR /&gt;print f $f&lt;BR /&gt;print g/$oldserver/s/$oldserver/$newserver/g&lt;BR /&gt;print w&lt;BR /&gt;done | ed&lt;BR /&gt;&lt;BR /&gt;to review the ed-commands use this last line:&lt;BR /&gt;...&lt;BR /&gt;done &amp;gt;/tmp/ed.cmd&lt;BR /&gt;&lt;BR /&gt;and then execute them via&lt;BR /&gt;&lt;BR /&gt;ed &lt;BR /&gt;Use 'ed -s' istead of 'ed' to suppress ed-output.&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;</description>
    <pubDate>Wed, 11 Jan 2006 14:33:59 GMT</pubDate>
    <dc:creator>Peter Nikitka</dc:creator>
    <dc:date>2006-01-11T14:33:59Z</dc:date>
    <item>
      <title>change a line in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707240#M103427</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have migrated some web application from one server to a new server.&lt;BR /&gt;&lt;BR /&gt;Now I have around 150 html files in which I have to change the server names.&lt;BR /&gt;&lt;BR /&gt;I know that I can use 'sed' to do it without opening the file but I will have to create a new file everytime I make change to an existing file.&lt;BR /&gt;&lt;BR /&gt;Can anyone please tell me a more suitable way to perform the changes in the file.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Anand</description>
      <pubDate>Wed, 11 Jan 2006 14:19:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707240#M103427</guid>
      <dc:creator>Anand_30</dc:creator>
      <dc:date>2006-01-11T14:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: change a line in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707241#M103428</link>
      <description>Hi Anand:&lt;BR /&gt;&lt;BR /&gt;Use perl and do in-place modification:&lt;BR /&gt;&lt;BR /&gt;# perl -i.old -pe 's/oldname/newname/g' file1 file2 ...&lt;BR /&gt;&lt;BR /&gt;If you don't want to preseve a pre-modified copy, do:&lt;BR /&gt;&lt;BR /&gt;# perl -i -pe 's/oldname/newname/g' file1 file2 ...&lt;BR /&gt;&lt;BR /&gt;That is, simply drop the argument (for example ".old") following the '-i' option.&lt;BR /&gt;&lt;BR /&gt;Multiple files can be specified at once as noted.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Jan 2006 14:26:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707241#M103428</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-11T14:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: change a line in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707242#M103429</link>
      <description>You can use ex to edit them in place.&lt;BR /&gt;&lt;BR /&gt;for FILE in list_of_files&lt;BR /&gt;do&lt;BR /&gt;ex ${FILE} &amp;lt;&lt;EOD&gt;&lt;/EOD&gt;1,$s/oldhostname/newhostname/g&lt;BR /&gt;wq!&lt;BR /&gt;EOD&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;(I think I remember the syntax of the substitution, but you might want to test it to be sure.)</description>
      <pubDate>Wed, 11 Jan 2006 14:31:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707242#M103429</guid>
      <dc:creator>Jeff_Traigle</dc:creator>
      <dc:date>2006-01-11T14:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: change a line in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707243#M103430</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;in this cases I generate ed-commands to do this.&lt;BR /&gt;Note1: Backup the files before you try!&lt;BR /&gt;Note2: use your appropriate method of getting the filenames&lt;BR /&gt;Note3: better tighten the pattern used for the global match (2nd print statement)&lt;BR /&gt;&lt;BR /&gt;oldserver=XXX&lt;BR /&gt;newseerver=YYY&lt;BR /&gt;for f in $(fgrep -l $oldserver *.html)&lt;BR /&gt;do&lt;BR /&gt;print f $f&lt;BR /&gt;print g/$oldserver/s/$oldserver/$newserver/g&lt;BR /&gt;print w&lt;BR /&gt;done | ed&lt;BR /&gt;&lt;BR /&gt;to review the ed-commands use this last line:&lt;BR /&gt;...&lt;BR /&gt;done &amp;gt;/tmp/ed.cmd&lt;BR /&gt;&lt;BR /&gt;and then execute them via&lt;BR /&gt;&lt;BR /&gt;ed &lt;BR /&gt;Use 'ed -s' istead of 'ed' to suppress ed-output.&lt;BR /&gt;&lt;BR /&gt;mfG Peter&lt;BR /&gt;</description>
      <pubDate>Wed, 11 Jan 2006 14:33:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707243#M103430</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-01-11T14:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: change a line in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707244#M103431</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;typo - change&lt;BR /&gt;for f in $(fgrep -l $oldserver *.html)&lt;BR /&gt;do&lt;BR /&gt;print f $f&lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt;print e $f&lt;BR /&gt;&lt;BR /&gt;mfG Peter</description>
      <pubDate>Wed, 11 Jan 2006 14:36:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707244#M103431</guid>
      <dc:creator>Peter Nikitka</dc:creator>
      <dc:date>2006-01-11T14:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: change a line in a file</title>
      <link>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707245#M103432</link>
      <description>Hi,&lt;BR /&gt;I use the ChanheSTring.ksh attched to perofrm this. It makes a backup copy of teh files changed and show you the line changed.&lt;BR /&gt;I love it.&lt;BR /&gt;HTH,&lt;BR /&gt;Art</description>
      <pubDate>Thu, 12 Jan 2006 04:12:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/change-a-line-in-a-file/m-p/3707245#M103432</guid>
      <dc:creator>Arturo Galbiati</dc:creator>
      <dc:date>2006-01-12T04:12:12Z</dc:date>
    </item>
  </channel>
</rss>

