Hi there, I'm pretty new to scripting and wondering if anyone had any idea's, scripts or snippets on how I can do the following.
I basically want a shell script that will look at all the files in a directory and find all the names and addresses in them then output them to the screen nicely formatted. Any help would be greatly appreciated...
Thanks, all solved now, however I want to do the same thing but generate a list of IP addresses that are in many different files within a directory using AWK, can you search for an IP string pattern?
thanks red, i'm beginning to see how powerful perl can be, never used it before. if i wanted to execute commands, such as ping each of those IP's, I can just create a simple 'for' loop:
for $1 do;
ping $1
something like that i'm guessing, not entirely sure of the syntax, maybe after that output it into nice columns such as 'Address' and 'Ping Result' will have a go. thx
In this case you don't have to use for. If you wish to ping, just:
perl -ne 'system "your-command $1" if /((?:\d{1,3}\.){3}\d{1,3})/;' ip-file
Now, it entirely depends on the actual content of your data file (ip-file). I created a pattern to match ip addresses /((?:\d{1,3}\.){3}\d{1,3})/ but if you have some data after the IP you could replace that pattern with /((?:\d{1,3}\.){3}\d{1,3})\s*(.*?)$/ so you have:
perl -ne 'print "$1\t$2\n" if /((?:\d{1,3}\.){3}\d{1,3})\s*(.*?)$/;' ip-file
that's pretty neat, i'm looking at doing a nslookup on those ip's too, that's easy to do but obviously generates lots of output, can I apply a pattern match once more to the results to just give me the IP and domain?
Can you mix system commands with the print command on just a single command line with perl?
All interesting stuff. I think i'm going to have to sit down and read up on perl pattern matching.