- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: for loop help
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
02-23-2001 09:01 AM
02-23-2001 09:01 AM
I would need help on the for loop to complete a file search,edit and save procedure.
I can make one command line working as expected as:
sed 's/'filesystem,null,null'/'filesystem,"''",null'/' aaa.fmb >bbb.fmb
But I cannot make it search and replace each of hundred of *.fmb files by using a shell script:
"for i in 'find -name *.fmb'
do sed 's/'filesystem,null,null'/'filesystem,"''",null'/' > /disk2/test2/i
done"
It should find next *.fmb file, execute sed, save the fmb file, then find next. I can figure out what parameter should be used as a majac.
Please help
Very appreciated.
Steven
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2001 09:06 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2001 09:07 AM
02-23-2001 09:07 AM
Re: for loop help
just saw tha you have no directory parameter within the find, so it should/could be:
for i in `find . -name *.fmb`
do sed 's/'filesystem,null,null'/'filesystem,"''",null'/' $i > /disk2/test2/$i
done
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2001 09:17 AM
02-23-2001 09:17 AM
Re: for loop help
If you know perl, you can use perl:
perl -p -i -e 's/searchstring/replacestring/' $(find . -name \*.fmb)
As you see, no need for a for loop. The above command does an in-place search and replace. No need to copy/re-copy your files.
If you require a backup of the original file, use the command
perl -p -i.bak -e 's/searchstring/replacestring/' $(find . -name \*.fmb)
This keeps the original file as .bak.
Hope this helps,
Rik.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2001 09:24 AM
02-23-2001 09:24 AM
Re: for loop help
Andreas:
I get error of:
sed: Cannot find or open file find.
sed: Cannot find or open file -name.
and one /disk2/test2/ I got a file name as
"find . -name *.fmb".
Please help.
Rik:
I could try Linux box that may have perl. Please tell me the how to use it, such as unix shell script first line as "#!/bin/sh, etc..
Very appreciated. I just want to have it worked!
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2001 01:41 AM
02-26-2001 01:41 AM
Re: for loop help
you have to take care what character you use at the find command:
The character has to be ` NOT '
If you use ' the command will not be executed.
Instead you have to use the ` character to execute the command.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2001 08:22 AM
02-26-2001 08:22 AM
Re: for loop help
I tested a few files that were changed as expected, which is good. But I can not have form program to open it, even though the filename not changed. I do see the file size become smaller.
Is there anyway to have sed to keep original pattern after changing just a word? There could be some parameter, g? or sth?
while *.fmb file can be open as text file, it should be OK with sed.
Thanks a lot,
Steven