- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: grep but not grep
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
05-24-2007 07:57 AM
05-24-2007 07:57 AM
I have the following files
a.cpp
b.cpp
b.h
c.cpp
c.h
file1
file2
x.html
x1.html
x2.html
y.xml
is there a way that I can grep all the files that have *.cpp extension and all the files that dont have the html extensions
ls -1 | grep [*.cpp|!*.html]
I know the !.html will not work..how do I fix it?
thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 08:07 AM
05-24-2007 08:07 AM
Re: grep but not grep
# ls -1 | grep ".cpp$"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 08:10 AM
05-24-2007 08:10 AM
Re: grep but not grep
ls -1 | grep -v -E '\.html$'
will list all files except those with .html suffixes. Note that the "\" is needed to escape the "." in regular expressions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 08:35 AM
05-24-2007 08:35 AM
Re: grep but not grep
I tried to give a simple example, but that is not what I wanted.
let me give a more closer to real life example
I have the following files
Makefile.defs@@/main/beta/0/Hijacked Makefile@@/main/beta/0
JBCINF.sbu
BCCOM.controller
alice33.cpp
file.cpp
I want to grap all the files except the files that end with @@/main/beta/0
please help out..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 08:36 AM
05-24-2007 08:36 AM
Re: grep but not grep
Makefile.defs@@/main/beta/0/Hijacked
Makefile@@/main/beta/0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 08:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 08:43 AM
05-24-2007 08:43 AM
Re: grep but not grep
# ls -1 | grep -v "@@/main/beta/0"$
The $ will anchor the string to the end of the line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 09:10 AM
05-24-2007 09:10 AM
Re: grep but not grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 01:45 PM - edited 10-01-2011 11:13 PM
05-24-2007 01:45 PM - edited 10-01-2011 11:13 PM
Re: grep but not grep
ls *.cpp would list all of the .cpp.
>I have the following files
Makefile.defs@@/main/beta/0/Hijacked
How can you get those files to show up in clearcase? ls -1 wouldn't ordinarily show multiple directory levels unless you used -R and it wouldn't descend into the @@ paths.
>I want to grab all the files except the files that end with @@/main/beta/0
You can use the shell Composite patterns:
ls -1 !(@@/main/beta/0)
- Tags:
- clearcase
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2007 07:51 PM
05-24-2007 07:51 PM
Re: grep but not grep
better to use:
grep -v \@\@/main/beta/0$ to be sure that teh search path be at the end.
HTH,
Art