- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 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
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
тАО06-09-2004 07:49 PM
тАО06-09-2004 07:49 PM
here my file: 156.152.45.5
156.152.45.58
156.152.45.589
and variable $ADRESSIP=156.152.45.5
i want to do a "grep" $ADRESSIP on my file
with only $ADRESSIP in the output and not
other word (not 156.152.45.58,156.152.45.589)
Thanks a lot.
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 07:55 PM
тАО06-09-2004 07:55 PM
Re: grep command
# grep '$ADRESSIP' file
Robert-Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 08:01 PM
тАО06-09-2004 08:01 PM
Re: grep command
You can do:
grep -w '$ADRESSIP' file
manish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 08:13 PM
тАО06-09-2004 08:13 PM
Re: grep command
grep "$ADRESSIP$" file
Note the $ at the end of the ADDRESSIP. This means that you will get any line that contains your IP address, followed by an end of line marker. This should exclude the other addresses from your search.
If that doesn't work, it may be that you have a space or tab character following the IP address. In this case, use
grep "$ADRESSIP " file
or
grep "$ADRESSIP
(use the TAB key rather than typing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 08:16 PM
тАО06-09-2004 08:16 PM
Re: grep command
grep -x $ADRESSIP file?
Using -x (eXact) Matches are recognized only when the entire input line matches the fixed string or regular expression.
RGDS
Mauro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 08:32 PM
тАО06-09-2004 08:32 PM
Re: grep command
It works for me:
$cat file
debug
debug1
$DF=debug
$grep -w $DF file
debug
As you can see debug1 is not displayed. It displays only the word which we are looking for.
manish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 08:36 PM
тАО06-09-2004 08:36 PM
Re: grep command
"grep -x and grep -w" not working !
Problem with patches ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 08:52 PM
тАО06-09-2004 08:52 PM
Re: grep command
$egrep -w $ADRESSIP file_name
$egrep -x $ADRESSIP file_name
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 09:36 PM
тАО06-09-2004 09:36 PM
Re: grep command
If you don't hate awk 8))):
awk `$1==A {print }' A=$ADDRESSIP $FILE
HTH
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-09-2004 11:23 PM
тАО06-09-2004 11:23 PM
Re: grep command
If you only need $ADRESSIP in the output, you can do a grep and if grep is successful then print the ip, for example:
ADRESSIP=156.152.45.5
grep $ADRESSIP file && echo $ADRESSIP
if no $ADRESSIP in file the command line output nothing, if $ADRESSIP in file the command line outputs the $ADRESSIP only
Frank.