- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- 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
07-18-2001 12:54 AM
07-18-2001 12:54 AM
For example if i make grep hp1 /etc/hosts i will see all ws that begins with hp1 so also hp12, hp110, hp19 and so on..
I want to find only hp1. I know that with sun the command is grep -w, but this doesn't exist on hp, what is it's correspondance? I looked in the grep's man, but i didn't find it. (maybe i didn't look well!!)
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 01:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 01:18 AM
07-18-2001 01:18 AM
Re: grep command
Try this :
grep 'hp1 ' /etc/hosts
Rgds
Alexander M. Ermes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 01:27 AM
07-18-2001 01:27 AM
Re: grep command
#!/sbin/sh
echo > /tmp/list
for i in 'cat /tmp/hplist'
do
grep $i /etc/hosts >> /tmp/list
done
I saw that if i put $i between '$i ', the output is wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 01:34 AM
07-18-2001 01:34 AM
Re: grep command
grep hp1$ /etc/hosts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 01:45 AM
07-18-2001 01:45 AM
Re: grep command
echo > /tmp/list
for i in 'cat /tmp/hplist'
do
grep $i$ /etc/hosts >> /tmp/list
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 01:50 AM
07-18-2001 01:50 AM
Re: grep command
grep "$i " ...
instead of
grep '$i ' ...
With single quotes your variable will not be translated, and grep will search for $i (dollar-i) in your file.
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 02:44 AM
07-18-2001 02:44 AM
Re: grep command
So the script isn't helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 03:11 AM
07-18-2001 03:11 AM
Re: grep command
where you type space followed by tab in the square brackets.
If this doesn't work, what type of expression is not being captured?
Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 03:19 AM
07-18-2001 03:19 AM
Re: grep command
grep -E "$i( | |$)" /etc/hosts
again, it's space,pipe,tab,pipe,dollar in the brackets.
Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 03:59 AM
07-18-2001 03:59 AM
Re: grep command
grep "hp1[ ]" hosts
The first character in the brackets is a space, the second character is where I pressed the tab key (on my system it actually show many more spaces) That way it will get those that end in spaces or those that end in a tab character.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 04:31 AM
07-18-2001 04:31 AM
Re: grep command
Here's what you could du using awk :
awk '
BEGIN {
while (getline <"/etc/hosts") {
for (i=1;i<=NF;i++) {
host[$i]=$0
}
}
while (getline <"/tmp/hplist") {
printf("%s\n",host[$0])
}
}' >/tmp/list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 04:55 AM
07-18-2001 04:55 AM
Re: grep command
I tried also yours Laurent, it works, but there are some entries that aren't found.
However i'd like to learn something about using awk, it seems very powerful, is there some tutorial on the net?
Thanks both, and of course thanks to all for your kindly help.
Regards
Tarek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2001 05:26 AM