- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find and remove a string(and its line)
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
тАО03-25-2008 02:01 AM
тАО03-25-2008 02:01 AM
in vi editor i used :%s/searchString/replace/g
but i would like to know how to remove that whole line of the search string.
i did :set list and it shows $ in the end of every line. but when i used $ like :%s/searchString$//g
its not working.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 02:14 AM
тАО03-25-2008 02:14 AM
Re: find and remove a string(and its line)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 02:19 AM
тАО03-25-2008 02:19 AM
Re: find and remove a string(and its line)
say this is my file:
----------
1
1
2
3
4
5
6
7
-----------
from this file i would like get a new file like this one:(search strings 3 and 5 removed with its lines)
-----------
1
1
2
4
6
7
------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 02:21 AM
тАО03-25-2008 02:21 AM
Re: find and remove a string(and its line)
ok, question is how to remove carriage returns or newline charactors in a file??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 02:25 AM
тАО03-25-2008 02:25 AM
Re: find and remove a string(and its line)
regards, Awadhesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 02:30 AM
тАО03-25-2008 02:30 AM
Re: find and remove a string(and its line)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 02:30 AM
тАО03-25-2008 02:30 AM
SolutionWhen you are in command mode in vi(1),
command "set list" displays
End-Of-Line characters as "$" sign.
To remove certain lines from file,
you can simply:
# egrep -v "^3|^5" origfile > newfile
or
# awk '! /^3|^5/ {print}' origfile > newfile
Many other ways exist.
Cheers,
VK2COT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 04:02 AM
тАО03-25-2008 04:02 AM
Re: find and remove a string(and its line)
Why not 'sed'?:
# sed -e '/3/d;/5/d' file
...removes any lines that have a 3 or a 5 somewhere on them (your example).
Whereas:
# sed -e '3d;5d' file
...removes line #3 and line #5 if that were your objective.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-25-2008 07:59 PM
тАО03-25-2008 07:59 PM
Re: find and remove a string(and its line)
You need:
:g/string/d
If you only want to remove "string" from a limited range, you can use:
:lineN,lineMg/string/d
>(search strings 3 and 5 removed with its lines)
You can do two passes or you can create a complex search string.
>question is how to remove carriage returns or newline characters in a file??
You can use "j" to join lines. You can use this to delete empty lines:
:g/^$/d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2008 01:24 AM
тАО04-02-2008 01:24 AM