- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help needed amending lots of files.
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
тАО09-02-2008 12:07 AM
тАО09-02-2008 12:07 AM
I have a requirement to remove certain lines from a large number of files.
The sections I need to remove are in the following format:
STRING
{
-options
-more options
}
So basically I need something that will find "STRING" and delete it and all lines down to and including the "}".
the number of "-options" can change in each file, so i can't specify deleting a fixed number of lines.
can awk do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2008 03:41 AM
тАО09-02-2008 03:41 AM
Solution# perl -ne 'print unless /^STRING/../^}/' file
...and if you want to update in place:
# perl -ni.old -e 'print unless /^STRING/../^}/' file
...which will preserve a backup copy as ".old". Drop the ".old" and leave a bare '-i' switch and no backup copy will be made, but the update will still be done in place.
Whille 'sed' doesn't allow in place edits, you can do:
# sed -ne '/^STRING/,/^}/!p' file > file.new
# mv file.new file
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2008 03:55 AM
тАО09-02-2008 03:55 AM
Re: Help needed amending lots of files.
Oh, and you asked specifically about 'awk'. That's quite similar, too:
# awk '/^STRING/,/^}/ {next};{print}' file
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2008 06:18 AM
тАО09-02-2008 06:18 AM
Re: Help needed amending lots of files.
Tnanks for all the suggestions, I've actually just found that awk solution with with a google search. It works perfectly.
Gonna have a play with perl now as I have no idea how to use it.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-02-2008 06:19 AM
тАО09-02-2008 06:19 AM