- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: change a line in a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2006 06:19 AM
тАО01-11-2006 06:19 AM
I have migrated some web application from one server to a new server.
Now I have around 150 html files in which I have to change the server names.
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.
Can anyone please tell me a more suitable way to perform the changes in the file.
Thanks,
Anand
Solved! Go to Solution.
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2006 06:26 AM
тАО01-11-2006 06:26 AM
SolutionUse perl and do in-place modification:
# perl -i.old -pe 's/oldname/newname/g' file1 file2 ...
If you don't want to preseve a pre-modified copy, do:
# perl -i -pe 's/oldname/newname/g' file1 file2 ...
That is, simply drop the argument (for example ".old") following the '-i' option.
Multiple files can be specified at once as noted.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2006 06:31 AM
тАО01-11-2006 06:31 AM
Re: change a line in a file
for FILE in list_of_files
do
ex ${FILE} <
wq!
EOD
done
(I think I remember the syntax of the substitution, but you might want to test it to be sure.)
Jeff Traigle
- Tags:
- ex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2006 06:33 AM
тАО01-11-2006 06:33 AM
Re: change a line in a file
in this cases I generate ed-commands to do this.
Note1: Backup the files before you try!
Note2: use your appropriate method of getting the filenames
Note3: better tighten the pattern used for the global match (2nd print statement)
oldserver=XXX
newseerver=YYY
for f in $(fgrep -l $oldserver *.html)
do
print f $f
print g/$oldserver/s/$oldserver/$newserver/g
print w
done | ed
to review the ed-commands use this last line:
...
done >/tmp/ed.cmd
and then execute them via
ed
Use 'ed -s' istead of 'ed' to suppress ed-output.
mfG Peter
- Tags:
- ed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2006 06:36 AM
тАО01-11-2006 06:36 AM
Re: change a line in a file
typo - change
for f in $(fgrep -l $oldserver *.html)
do
print f $f
to
print e $f
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2006 08:12 PM
тАО01-11-2006 08:12 PM
Re: change a line in a file
I use the ChanheSTring.ksh attched to perofrm this. It makes a backup copy of teh files changed and show you the line changed.
I love it.
HTH,
Art