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
Forums
Discussions
Discussions
Discussions
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
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-2007 10:26 AM
01-11-2007 10:26 AM
find . -name "*.*"|xargs grep "/var/log/test"
Can I make a change thru command line instead of going into each and every file . I am looking for an exact answer.
thanks,
hunki
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 10:34 AM
01-11-2007 10:34 AM
Re: Query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 10:50 AM
01-11-2007 10:50 AM
SolutionUse Perl and you can make your updates inplace while creating a backup copy of the original files:
# perl -pi.old -e 's%/var/log/test\b%/var/log/prod%g' file1 file2 file3 ...
This will replace the string "/var/log/test" with "/var/log/prod" in every file passed as an argument. For each file (argument) the original file will be preserved as "*.old".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 10:54 AM
01-11-2007 10:54 AM
Re: Query
.....
for i in `find . -type f \
| xargs -i grep -l "\/var\/log\/test" {} `
do
echo ------ fixing file $i -------
cat $i | sed "s/\/var\/log\/test/\/var\/log\/prod/" > $i.new
# Uncomment the following lines to remove
# to remove the .new file if you are
# comfortable with how this thing works,
# and have seen it run sucessfully for a
# while, otherwise it probably does no harm
# to leave it - providing there are no
# security or space issues in leaving the
# these files in place.
# rm $i.new
done
If you need to actually have the new file replace the old one (instead of just having a new file with the ".new" extension on it).
for i in `find . -type f \
| xargs -i grep -l "\/var\/log\/test" {} `
do
echo ------ fixing file $i -------
cat $i | sed "s/\/var\/log\/test/\/var\/log\/prod/" > $i.new
cp $i $i.old.keep.bak
cp $i.new $i
# Uncomment the following lines to remove
# to remove the .new file and the backup file
# if you are comfortable with how this thing
# works, and have seen it run sucessfully for
# a while, otherwise it probably does no harm
# to leave it - providing there are no
# security or space issues in leaving the
# these files in place.
# rm $i.new
# rm $i.old.keep.bak
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2007 03:23 PM
01-11-2007 03:23 PM
Re: Query
use strict;
use warnings;
while (
my $count = 0;
my $file = $_;
my @lines;
open (OLD, "<$file");
while (
$count += s%/var/log/test\b%/var/log/prod%g;
push @lines, $_;
}
close OLD;
if ($count) {
$_ = $file;
s/\..*?$/.old/;
rename $file, $_;
open (NEW, ">$file");
print NEW @lines;
close NEW;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2007 03:41 AM
01-12-2007 03:41 AM