- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: scripting help with find
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
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
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-23-2012 09:30 AM
01-23-2012 09:30 AM
Hi there,
I have the following shell in a RHEL 4 Server:
export DIR=/u01
for dir in `find $DIR -type d`;
do
grep pattern $dir/*;
done
As the above script gives thousands of files I'm looking for help to actually find the pattern and also change it for another string.
Any help will be appreciated
Solved! Go to Solution.
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2012 12:00 PM
01-23-2012 12:00 PM
Re: scripting help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2012 01:04 PM - edited 01-23-2012 01:05 PM
01-23-2012 01:04 PM - edited 01-23-2012 01:05 PM
Re: scripting help with find
>As the above script gives thousands of files
1000s of files as in you want to automate it? Or you just want to limit it?
If you have a shell pattern match instead of a grep RE, you can use -name:
DIR=/u01
find $DIR -type f -name "pattern" | while read file; do
# do something with filename ...
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2012 01:24 PM
01-23-2012 01:24 PM
Re: scripting help with find
I want to automate it. Let me explain a bit more the current state:
I have just virtualized a production environment (RHEL 4 running oracle application server). It's a production environment for the purpose of making a development environment. It's something I never did before and also I don't know how OAS works.
So I thought it it would be easier to change the virtual server hostname and replace the original server name for the virtual of all files containing the name of the production system.
Answering your question I want to automate the process of find all the files containing the prod server hostname, edit each one of them in order to get all of these files "pointing" to the new virtual server's hostname.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2012 01:42 PM
01-23-2012 01:42 PM
Re: scripting help with find
Maybe something like this:
for dir in `find $OAS -type d`;
do
FILE=`grep $SOURCE_HOSTNAME $dir/*`;
if [ $FILE ]; then
/bin/cat - << EOF | /bin/ed -s $FILE
1,$ s/$SOURCE_HOSTNAME/$TARGET_HOSTNAME/g
w $FILE
q
EOF
FILE=\0
fi
done
But above doesn't work yet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2012 08:50 PM
01-23-2012 08:50 PM
Solution>find all the files containing the prod server hostname, edit each one of them in order to get all of these files "pointing" to the new virtual server's hostname.
DIR=/u01
find $DIR -type f | while read file; do
fgrep -q "$SOURCE_HOSTNAME" $file
if [ $? -eq 0 ]; then
sed "s/$SOURCE_HOSTNAME/$TARGET_HOSTNAME/g" $file > $file.new &&
mv $file.new $file # permission & ownership possibly changed
fi
done
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2012 07:56 AM
01-24-2012 07:56 AM
Re: scripting help with find
Thank's for your support dennis, that did the trick!.
Regards!