- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Upload 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
Forums
Discussions
Discussions
Forums
Discussions
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
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
08-22-2004 03:10 PM
08-22-2004 03:10 PM
I want to replace all the word "SUCCESS" to "FAIL" in all files under the directory /home ( include all sub-directories ) , what can I do ? thx in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2004 04:44 PM
08-22-2004 04:44 PM
Re: Upload file
Here's a really quick/dirty way to do it. I'm sure there are many more elaborate ways, and several more checks you can add to make it work to your liking:
for FILE in $(find /home/.)
do
if [ ! -x $FILE ]
then
grep "SUCCESS" $FILE > /dev/null 2>&1
if [ $? -eq 0 ]
then
cat $FILE | sed "s/SUCCESS/FAIL/g" > $FILE.new
fi
fi
done
This script checks to see that the file is not an executable and it ensures that the string "SUCCESS" appears in the file before modifying it. The original file is left intact and a new file with a ".new" extension is created.
Good luck,
Dave
I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2004 05:26 PM
08-22-2004 05:26 PM
SolutionTake a look at this link:
http://www.dslreports.com/forum/remark,10607506~mode=flat
HTH.
Regards,
Sri Ram
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2004 06:14 PM
08-22-2004 06:14 PM
Re: Upload file
I try the methods is ok, but it will copy a backup to $FILE.bak , how can I directly update the files instead of make a backup file ? thx.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2004 03:43 AM
08-23-2004 03:43 AM
Re: Upload file
If you wanted to use the logic I posted previously, just change the line:
cat $FILE | sed "s/SUCCESS/FAIL/g" > $FILE.new
to
cat $FILE | sed "s/SUCCESS/FAIL/g" > $FILE
That will replace the existing file with the modified content.
Regards,
Dave
I work at HPE
HPE Support Center offers support for your HPE services and products when and how you need it. Get started with HPE Support Center today.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2004 06:34 PM
08-24-2004 06:34 PM
Re: Upload file
find /home -type f -exec perl -pi -e 's,SUCCESS,FAIL,g' {} \;
Be careful with
cat $FILE | sed "s/SUCCESS/FAIL/g" > $FILE
I think shell will process redirections before executing any commands. Which means that $FILE will get clobbered before cat gets to it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2004 07:37 PM
08-24-2004 07:37 PM
Re: Upload file
Perl is easy to do as,
perl -p -i -e 's/SUCCESS/FAIL/g' filename.
You can collect all files using find command as,
find
You can do it with sed as
echo "sed -e 's/SUCCESS/FAIL/g' filename" > filename
It will do the changes for one file with using temp. files.
You can do on multiple files as,
grep -l "SUCCESS"
It will change all patterns of SUCCESS on all files. If you want to know what is happeneing just remove | sh on execution it will print single file execution statements for all files.
Regards
Muthu