- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to get only the line indicated with "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
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
тАО02-04-2011 10:27 PM
тАО02-04-2011 10:27 PM
i am in / ... into / there are the following directories and fiiles:
dr-xrwxrwx 5 bin bin /usr
drwxrwxrwx 5 bin bin /usr/user1
drwxrwxrwx 5 bin bin /usr/user2/b.txt
drwxrwxrwx 5 bin bin /usr/user3/a.txt
drwxrwxrwx 5 bin bin /usr/company1/
drwxrwxrwx 5 bin bin /usr/company1/user4
drwxrwxrwx 5 bin bin /usr/company1/user5
if i list /usr i get:
i am under /
ls -lrt | grep /usr .... i get all the lines that contains "/usr" ...
dr-xrwxrwx 5 bin bin /usr
drwxrwxrwx 5 bin bin /usr/user1
drwxrwxrwx 5 bin bin /usr/user2/b.txt
drwxrwxrwx 5 bin bin /usr/user3/a.txt
drwxrwxrwx 5 bin bin /usr/company1/
drwxrwxrwx 5 bin bin /usr/company1/user4
drwxrwxrwx 5 bin bin /usr/company1/user5
but i only want to get theline that only contains "/usr" as follows:
dr-xrwxrwx 5 bin bin /usr
and .. how about if i only want to get the line that says: /usr/company1/
ls -lrt | grep "/usr/company1/"
i only want to get:
drwxrwxrwx 5 bin bin /usr/company1/
and not all the lines below ...
drwxrwxrwx 5 bin bin /usr/company1/
drwxrwxrwx 5 bin bin /usr/company1/user4
drwxrwxrwx 5 bin bin /usr/company1/user5
please your help, thanks in advance.
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-04-2011 11:02 PM
тАО02-04-2011 11:02 PM
SolutionFor your case just try adding a blank space before last double quotes:
#ls -lrt | grep "/usr/company1/"
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2011 12:36 AM
тАО02-05-2011 12:36 AM
Re: How to get only the line indicated with "grep" ...
If you are looking for directories, you are going about this wrong. Use -d to only list the one directory: ll -d /usr /usr/company
But if you are practicing grep, you can look into -w or -x.
>Jose: For your case just try adding a blank space
That's not likely to work since there isn't a blank at the end of the line. You can use "$" as the end of line anchor instead:
ls -lrt | grep "/usr/company1/$"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-06-2011 06:01 AM
тАО02-06-2011 06:01 AM
Re: How to get only the line indicated with "grep" ...
never mind if it is a directory or file .. i mean, i am doing a loop and there i do not specify if it is a directory or not ... i only get the line with that word "/usr/company1/" the problem here is i get the 5 lines below when i use "grep", i forget tell you i have files under those directories ...
drwxrwxrwx 5 bin bin /usr/company1/
drwxrwxrwx 5 bin bin /usr/company1/user4
drwxrwxrwx 5 bin bin /usr/company1/user5
-rwxrwxrwx 5 bin bin /usr/company1/user5/file1
-rwxrwxrwx 5 bin bin /usr/company1/user5/file2
if i want to get the line with "/usr/company1/" i only want to get
drwxrwxrwx 5 bin bin /usr/company1/ and not the 5 lines .. how can i do that? what command or parameter can i use?
thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-06-2011 07:08 AM
тАО02-06-2011 07:08 AM
Re: How to get only the line indicated with "grep" ...
That's important. If you don't want to expand directories, add that -d. (It doesn't change how non-directories are displayed.)
>how can I do that? what command or parameter can I use?
As I said above, adding -d would be easier. Or you can use "$" in the grep.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-06-2011 07:48 AM
тАО02-06-2011 07:48 AM
Re: How to get only the line indicated with "grep" ...
It is worth your noting that in addition to limiting matches to a string that is anchored (pinned) to the end of a line, you can also match a string only if it is anchored to the beginning of a line.
The '$' as the last character of a regular expression anchors the match to the end of a line.
The '^' as the first character of a regular expresson anchors the match to the beginning of a line.
Hence, as noted, to match '/usr/company/1' in your example, you could do:
# ... grep /usr/company/1$
If you had a 'ls -l' listing of both files and directories, you could match only files, for example, by doing:
# ls -l | grep ^-
...since files are listing on a line that begins with a '-'. Correspondingly, since symbolic links begin with 'l', this would find those:
# ls -l | grep ^l
For much much more about regular expressions, see the manpages for 'regexp(5)'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-06-2011 10:05 AM
тАО02-06-2011 10:05 AM
Re: How to get only the line indicated with "grep" ...
long story short:
use
ls -lrt ... | grep '/usr/company1/$'
or if there may or may not a "/" at the end of your string
ls -lrt ... | grep '/usr/company1/*$'
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2011 03:06 PM
тАО02-07-2011 03:06 PM
Re: How to get only the line indicated with "grep" ...
ls -lrt ... | grep '/usr/company1/*$'
thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-07-2011 11:44 PM
тАО02-07-2011 11:44 PM
Re: How to get only the line indicated with "grep" ...
I mean:
# ls -lrt ... | grep '/usr/local/*$'
... not found
# ls -lrt | grep '/usr/local/*$'
but;
# cd
# ls -lR | grep "/usr/local/*"
./usr/local/include:
./usr/local/lib:
./usr/local/man:
./usr/local/man/de:
(you need to put company1 instead of local)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-08-2011 12:13 AM
тАО02-08-2011 12:13 AM