- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- what is the problem with grep -x here.
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-02-2006 09:22 PM
05-02-2006 09:22 PM
So i tried this command and got the answer.
bash-2.02# ls -i / | grep 2
128674 .osuuid
6521 .ssh
87726 bin
125345 core
261 dev
125464 mnt
6525 nfsmount
283 opt
135620 performix.pl
2 stand
138942 state
136697 tc2.sh
2671 temp
12 tmp
bash-2.02# ls -i / | grep -x 2
But, why grep -x is not giving me the exact answer.
Thanks & regards,
Prasad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:26 PM
05-02-2006 09:26 PM
Re: what is the problem with grep -x here.
you have to 'anchor' the grep:
ls -i / | grep '^2 '
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:28 PM
05-02-2006 09:28 PM
Re: what is the problem with grep -x here.
Use ls -il |grep -x 2
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:29 PM
05-02-2006 09:29 PM
Re: what is the problem with grep -x here.
sorry, my previous answer only works if the '2 ' is right at the start of the line.
Perhaps better:
ls -i1 / | grep ' 2 '
No points for this part of the answer, please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:29 PM
05-02-2006 09:29 PM
Re: what is the problem with grep -x here.
I tried this
bash-2.02# ls -i / | grep -x '^2'
But, this does not give the expected answer.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:31 PM
05-02-2006 09:31 PM
Re: what is the problem with grep -x here.
bash-2.02# ls -i / | grep -x 2
bash-2.02# ls -i / | grep -x "^2"
bash-2.02# ls -i / | grep -x '^2'
bash-2.02# ls -i / | grep -x '2'
bash-2.02# ls -i / | grep -x ' 2 '
bash-2.02# ls -il / | grep -x ' 2 '
bash-2.02# ls -il / | grep -x 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:33 PM
05-02-2006 09:33 PM
Re: what is the problem with grep -x here.
ths -x only works if the WHOLE line matches.
grep 2 return any line that has the number 2 in it. Doing the ' 2 ' means, only return the lines with space-2-space.
man grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:35 PM
05-02-2006 09:35 PM
Re: what is the problem with grep -x here.
(eXact) Matches are recognized only when the
entire input line matches the fixed string orregular expression.
the entire input line of 2 includes stand.
Robert-Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:36 PM
05-02-2006 09:36 PM
Re: what is the problem with grep -x here.
The answer is actually very simple.
Please read the man page of grep carefully - to understand the -x options.
-x is used to match the exact line, thus when you are just gicing 2 and there are so many other characters/words on the same line - so the exact match for 2 fails.
Just to understand better do a small experiment.
so a grep -il | grep -x 2
Now once you get the output do
grep -il | grep -x "the whole line copy pasted"
Paste any of the lines - the whole line in above command , including starting spaces etc.
Ans you will understand,
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:37 PM
05-02-2006 09:37 PM
Re: what is the problem with grep -x here.
use the below
ls -il / |awk '{print $1}'|grep -x 2
testos:/opt/omni/etc # ls -il / |awk '{print $1}'|grep -x 2
2
2
2
2
2
2
2
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:37 PM
05-02-2006 09:37 PM
Re: what is the problem with grep -x here.
How to find the file system which has some specific inode, 2 in this case.
Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:48 PM
05-02-2006 09:48 PM
Re: what is the problem with grep -x here.
This is very good learning experience.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2006 09:49 PM
05-02-2006 09:49 PM
Re: what is the problem with grep -x here.
# cat /etc/fstab | awk '{ print $2 }' | while read LINE
do
ls -ild $LINE
done
Regards,
Robert-Jan