- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How can I delete entire lines based on a searc...
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
09-05-2011 03:24 AM - edited 09-05-2011 04:32 AM
09-05-2011 03:24 AM - edited 09-05-2011 04:32 AM
I need to remove the following lines from a file:
<AccountType>Some stuffs in here also</AccountType>
How can I do this with vi or another hpux program?
Thank you,
Eric Antunes
Solved! Go to Solution.
- Tags:
- vi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2011 04:44 AM
09-05-2011 04:44 AM
SolutionAssuming the (XML like) lines are all on a single line each:
In vi
:g/<AccountType>/d
With perl:
$ perl -ni -e'm/ <AccountType>/ or print' file.txt
But that is only safe if there is onlo what you show on a single line. If text folds and the closing tag is on the next line, or if other text is on the same line, this is going to fail.
Is the whole file valid HTML? or XML?
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2011 04:57 AM
09-05-2011 04:57 AM
Re: How can I delete entire lines based on a search expression in vi?
It worked! This is a valid XML file but I need to remove that part in the entire file.
Thank you,
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2011 05:06 AM - edited 09-05-2011 05:28 AM
09-05-2011 05:06 AM - edited 09-05-2011 05:28 AM
Re: How can I delete entire lines based on a search expression in vi?
><AccountType>Some stuff in here also</AccountType>
You can be more pedantic:
:g:<AccountType>.*</AccountType>:d
If you need to anchor the lines to beginning and end:
:g:^<AccountType>.*</AccountType>$:d
And you can use these in sed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2011 05:19 AM
09-05-2011 05:19 AM
Re: How can I delete entire lines based on a search expression in vi?
If you want to be more pedantic, please escape the inside slash :)
:g/<AccountType>.*<\/AccountType>/d
If you need to anchor the lines to beginning and end:
Assuming \s is whitespace in your editor, and it supports * for greedy and ? non-greedy modifiers
:g/^\s*<AccountType>.*?<\/AccountType>\s*$/d
Otherwise greedy .* might get way to much :)
And you can (maybe) use these in sed (depending on what version od sed you have).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2011 05:32 AM - edited 09-05-2011 05:32 AM
09-05-2011 05:32 AM - edited 09-05-2011 05:32 AM
Re: How can I delete entire lines based on a search expression in vi?
>If you want to be more pedantic, please escape the inside slash :)
Oops, done, replaced by a colon ":". :-(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2011 07:51 AM
09-05-2011 07:51 AM
Re: How can I delete entire lines based on a search expression in vi?
I don't need to be pedantic. :-)
Thank you guys.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2011 09:04 AM
09-05-2011 09:04 AM
Re: How can I delete entire lines based on a search expression in vi?
@Eric Antunes wrote:I don't need to be pedantic. :-)
Learning precision when deploying regular expressions will keep you from matching when you *don't* want to match as well as allow you to match when you should. Form the good habits early and save yourself countless hours of pain.
Regards!
...JRF...
- Tags:
- regex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2011 03:53 AM
09-12-2011 03:53 AM
Re: How can I delete entire lines based on a search expression in vi?
Hi again,
I didn't need to be pedantic since this is a XML file with serious parse errors. So, things like <AccountType>,<EMail/>, <Contact/>... could safely be removed. But now it gets harder (at least for me, a DBA): I need to add stuffs to the file.
For example, I would like to add the line "<SelfBillingIndicator>0</SelfBillingIndicator>" before each line "</Customer>"
How can I do that in vi?
Thank you,
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2011 05:20 AM
09-12-2011 05:20 AM
Re: How can I delete entire lines based on a search expression in vi?
@Eric Antunes wrote:For example, I would like to add the line "<SelfBillingIndicator>0</SelfBillingIndicator>" before each line "</Customer>"
How can I do that in vi?
Using 'vi' search for the first line with "Customer":
Insert your "SelfbillingIndicator" line above it by (O)pening a new line above it.
After you have inserted the new line, yank (yy) a copy of it.
Hit 'n' to continue to search forward for "Customer" and when you reach a matching line, use 'P' to put the yanked buffer above the "Customer" line.
Regards!
...JRF...