- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: strange behavior using grep command
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
09-22-2021 10:53 PM - last edited on 09-23-2021 04:47 AM by support_s
09-22-2021 10:53 PM - last edited on 09-23-2021 04:47 AM by support_s
Hi,
here is my input file
sanvg1::::lv_logiciel /logiciel
sanvg1::::loglv00 N/A
sanvg1::::lv_oradiag /logiciel/app/oracle/diag
sanvg1::::lv_exp0x00 /exp0x00
sanvg1::::lvbase /base
I need to grep /logiciel
but
cat myfile | grep -w "/logiciel"
returns /logiciel but also /logiciel/app/oracle/diag
How to grep the exact substring ?
Thanks in advance,
Kind regards,
Den.
Solved! Go to Solution.
- Tags:
- Operating System
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2021 03:40 AM
09-23-2021 03:40 AM
SolutionHere's the man page for the -w option of grep:
-w Select only those lines containing matches
that form whole words. The test is that the
matching substring must either be at the
beginning of the line, or preceded by a nonword
constituent character. Similarly, it
must be either at the end of the line or
followed by a non-word constituent character.
Word-constituent characters are letters,
digits, and the underscore.
So "/" is a "non-word consituent character", so it is considering the "/logiciel" part to be a seperate word from "/app/oracle/diag" (which it would also consider seperate words)
Quick and dirty fix I guess would be that as you know the field you want to match on is at the end of the line you could instead use
grep "/logiciel$" myfile
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2021 04:59 AM
09-23-2021 04:59 AM
Re: strange behavior using grep command
Hi Duncan,
Thank you so much.
Not so dirty!
In fact my code is now something like that, so I tested your trick and it works.
VG=`echo "$theLVlist" | grep -w "${FS}$" | awk -F "::::" '{print $1}'`
Kind regards,
Den.