grep specific ipaddress from a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep specific ipaddress from a file
# 1  
Old 11-19-2011
Question grep specific ipaddress from a file

All,
Iam new to unix and i have 1 requirement, can anyone help me please
I have provided the file below, i will be having similar files in 100+clients systems. i want to check the the ip address "192.168.208.40" and if it is present then i should get a mail alert, if the ip address is not present then i should not get an alert

Please let me know if you need any other details
Code:
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. 
#
#      102.546.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
127.0.0.1       localhost
# Set the a.b.c values according to the value        
-- More  --
# in the ControlPannel->Network Applet !                  
#a.b.c.d.1        S1                                   
#a.b.c.d.2        S2                                      
#a.b.c.d.3        S3         
#a.b.c.d.10       LFS10                                     
#a.b.c.d.111     POS1                                      
#255.255.255.0  SUBNETMASK                                
#
255.255.240.0     SUBNETMASK                              
166.70.1.1.     TS09735ISS01 MFFS001                         
166.70.1.2       TS09735ISS02 MFFS002
166.70.0.1       LFtrhS10 RSTU6000
#                                                         
# Camelot Server                                          
192.168.208.40  test.gw.camelotinteractive.com
#                        
#
172.21.178.75   pvuksavsec005                             
172.21.178.101  pvuksavsum021        
#                                                 
#


Last edited by Scott; 11-19-2011 at 06:48 AM.. Reason: Code tags
# 2  
Old 11-20-2011
Re: grep specific ip address

Do you mean to script a test? Maybe try this:

grep "192.168.208.40" /etc/hosts >/dev/null && mail userX < /etc/hosts

So, if the "grep" is successful ("&&") then mail "userX" the file.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a log file starting from a specific time to the end of file

I have a log file which have a date and time at the start of every line. I need to search the log file starting from a specific time to the end of file. For example: Starting point: July 29 2018 21:00:00 End point : end of file My concern is what if the pattern of `July 29 2018 21:00:00`... (3 Replies)
Discussion started by: erin00
3 Replies

2. UNIX for Beginners Questions & Answers

Help with Grep Specific Date From One File Into A New One

Hello All, First post, don't know much about Linux/Unix, but I need some help. Normally, I do grep 'what I'm searching for' FILE > file.txt so I can pull data from one file, and put it into a new one. The issue I am having is with specific dates, since the date field is 4, and it appears... (3 Replies)
Discussion started by: DennisG34
3 Replies

3. Shell Programming and Scripting

Grep in a specific file in an archive

Hi all, I need to do a grep in a specific file inside multiple (tar.gz) archives. I know zgrep can grep in an archive, but as far as I know, I can't supply a specific filename from inside the archive to grep in. Is there any other way do to this, besides extracting it and then... (1 Reply)
Discussion started by: Subbeh
1 Replies

4. Shell Programming and Scripting

Fetch ipaddress and hostname from host file.

hello guys, I have a query ,I am looking for a unix command using awk and grep that help me fetching a particular ip address and hostname from the host file.........?????? (3 Replies)
Discussion started by: Pawan Ramnani
3 Replies

5. UNIX for Dummies Questions & Answers

Grep from specific column in one file based on another file [Please help!]

Hey Guys, to keep it simple, I have an idFile: 1006006 1006008 1006011 1007002 ...... and famFile: 1006 1006001 1006016 1006017 1 1006 1006006 1006016 1006017 1 1006 1006007 0 0 2 1006 1006008 1006007 1006006 2 1006 1006010 1006016 1006017 2 1006 1006011 1006016 1006017 1 1006... (2 Replies)
Discussion started by: Zoho
2 Replies

6. Shell Programming and Scripting

Help with grep at specific field of a file

hi, I would like to search for a specific string at a specific line in a file and would like to know the count of it. eg: samp.txt ABC 1234 BELL HNZ 4567 RING NNN 5673 BELL Please help with the command to find the count of BELL in the above file samp.txt at the specific line 10 with... (7 Replies)
Discussion started by: techmoris
7 Replies

7. Shell Programming and Scripting

grep a specific line from a file

Is there a way to grep only one line from a file listing name of files? If I use head -1 it's ok(the first line only) If I use head -2 it's not good because I have already checked the first line. I'd like something like this: while test $i -le $max do grep "$3" `head -$i temp.txt` >... (4 Replies)
Discussion started by: Max89
4 Replies

8. Shell Programming and Scripting

retrieving specific lines from a file - can I use grep ?

Hi there, if i had a file that looked like this my_server1 red green blue yellow blue my_server2 blue blue yellow green blue my_server3 yellow (9 Replies)
Discussion started by: hcclnoodles
9 Replies

9. Shell Programming and Scripting

grep on specific line of the file

Hi, how can we search for a word (with case ignore )on specific line numbers ex: Awk /^regEX/ with condition on first line or second line Awk/^ regex1/ on line 1 Awk /^regEX2/ on line 3 thanks in advance (4 Replies)
Discussion started by: rider29
4 Replies

10. UNIX for Dummies Questions & Answers

How do I grep in specific file types?

I have a directory with file types ending .log, .mml, .gll, .dll . How can I grep expressions only in say the .log files? (3 Replies)
Discussion started by: bbbngowc
3 Replies
Login or Register to Ask a Question