- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: sed problem
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
тАО07-22-2007 10:37 PM
тАО07-22-2007 10:37 PM
1) Search a file for a block of text
2) Search a file for the first occurance of a string
3) Insert a block of text
I've tried various combonations of sed commands with little luck so any help appreciated
Thanks in advance
Declan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 12:19 AM
тАО07-23-2007 12:19 AM
Re: sed problem
sed s/string_you_search_for/new_string\ string_you_search_for/ filename
This should print on STDOUT the result. If you wish to modify the content of the file as well, then simply redirect the output to some file and then rename the new file to the name of the original file ( after you did a backup of the original file of course).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 12:36 AM
тАО07-23-2007 12:36 AM
Re: sed problem
I only want to replace the first occurance of the word and i need to replace it with a block of text.
my file is like this
Declare
Begin
EXECUTE IMMEDIATE 'BEGIN WriteScriptsLogs( :2, :3, :4, :5, :6, :7, :8, :9 ); END;'
USING IN s_Source, IN s_ScriptName, IN s_ScriptSetVer, IN s_SetRange, IN n_ScriptVer
, IN s_Status, IN s_Message, OUT s_Return;
End;
I need to search for the EXECUTE IMMEDIATE block until the s_Return and replace it with another different block
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 01:36 AM
тАО07-23-2007 01:36 AM
Re: sed problem
If you don't mind Perl:
# perl -0377 -pe 's/EXECUTE IMMEDIATE.+s_Return/NEW\nBLOCK\nHERE/s' file
If you would like to update the file "in-place", retraining an un-modified backup copy as "file.old", do:
# perl -0377 -p.old -e 's/EXECUTE IMMEDIATE.+s_Return/NEW\nBLOCK\nHERE/s' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 01:58 AM
тАО07-23-2007 01:58 AM
Re: sed problem
I don't mind using perl but i had to change the command slightly by removing the .old after the -p otherwise i got the following error
Unrecognized switch: -.old (-h will show valid options).
now i output the result to a second file
any idea how to search for the first occurance of a word in the same file i.e. if i have multiple blocks which are the same?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 03:06 AM
тАО07-23-2007 03:06 AM
Re: sed problem
Sorry, I droppted a ".":
# perl -pi.old -e ...
Anyway, for your first-only block:
# perl -0377 -pi.old -e 's/EXECUTE IMMEDIATE.+s_Return;(.+Declare.+)/NEW\nBLOCK\nHERE\1/s' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 04:16 AM
тАО07-23-2007 04:16 AM
Re: sed problem
Actually, I prefer:
# perl -0377 -pi.old -e 's/(EXECUTE IMMEDIATE.+s_Return;)(?=.+EXECUTE IMMEDIATE.+s_Return;)/NEW\nBLOCK\nHERE/s' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 04:26 AM
тАО07-23-2007 04:26 AM
Re: sed problem
I'll give this a whirl asap and assign point.
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2007 11:46 PM
тАО07-23-2007 11:46 PM
SolutionDisregard yesterday's bungles, please. I was not thinking clearly at all! The following should work for one or n-blocks of text as you have shown:
# perl -0377 -pi.old -e 's/(EXECUTE IMMEDIATE.+?s_Return;)/NEW\nBLOCK\nHERE/s' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-24-2007 01:09 AM
тАО07-24-2007 01:09 AM
Re: sed problem
Thanks again