473,472 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

improrting more than one file and matching

123 New Member
Hey all,
I have one folder in our shared document drive .
In that folder , there are text files(Included time stamps) like systems_14475383.txt
and systems_15354781etc
That all file contains IP address . Now how can I wirte a perl script to have IP address from each of them ??
Any Idea?
Thanks,
Jul 10 '08 #1
4 1271
nithinpes
410 Recognized Expert Contributor
To give you some hints; use opendir() and readdir() functions to open the folder and get the files inside it, respectively. Parse through each file using open(). Read each file and extract IP addressses using regular expression.
Write your script and post it here if you face any issues..

- Nithin
Jul 11 '08 #2
ajd335
123 New Member
To give you some hints; use opendir() and readdir() functions to open the folder and get the files inside it, respectively. Parse through each file using open(). Read each file and extract IP addressses using regular expression.
Write your script and post it here if you face any issues..

- Nithin
Hey Nithin,
I cant open the DIR at first...
i am working on perl on /home/ajd/data/ip.pl where I am writing the script
and the dir which I need to open is in shared folder of \\cde\groups\document\IP
Other directories I can open , But how can I open the above one..
Thanks
Jul 11 '08 #3
nithinpes
410 Recognized Expert Contributor
Hey Nithin,
I cant open the DIR at first...
i am working on perl on /home/ajd/data/ip.pl where I am writing the script
and the dir which I need to open is in shared folder of \\cde\groups\document\IP
Other directories I can open , But how can I open the above one..
Thanks
Use:
Expand|Select|Wrap|Line Numbers
  1. opendir(DIR,"\\\\IP\\cde\\groups\\document") or die "cannot open directory:$!"; 
  2.  
If you face any difficulty again, post your code and also any error message that you are getting, for further assistance.
Jul 14 '08 #4
ajd335
123 New Member
Use:
Where it printed "array()" 10 times means that you have 10 files in that directory but you never matched anything from your preg_match().

Just for fun, replace print_r($matches) with var_dump($lines) and tell me what you get? Not sure if that gives you line by line or the whole file. Also, you may need a 'g' pattern modifier to turn on global pattern searching.

Hi Bretticus ,
It was a small mistake why the answer was not showing up...
I have the below code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $dirname = "/home/ajd/ip";
  3. if($handle = opendir($dirname))
  4. {
  5.     while(false !== ($filename = readdir($handle))){
  6.         if (is_readable($filename)) {
  7.   if ($handle1 = fopen($filename, "r") ) {
  8.                 while(!feof($handle1)) {
  9.                     $lines = fgets($handle1);
  10. if(preg_match('/ Host Name . . . . . . . . . . . . :(.*)$/',$lines,$matches))
  11.  {
  12.        print_r($matches[1]);
  13.         echo ",";
  14.  }
  15.  
  16.  
  17. if(preg_match('/IP Address. . . . . . . . . . . . : 10.(.*)$/',$lines,$matches))
  18. {  $ad = "10.";
  19.  print_r($ad.$matches[1]); 
  20. }
  21. if(preg_match('/Physical Address. . . . . . . . . :(.*)$/',$lines,$matches))
  22.  {
  23. print_r($matches[1]);
  24. echo ",";
  25.  
  26. }
  27. }                fclose($handle1);
  28.             } } } 
  29.  
  30.     closedir($handle);
  31. }
  32. ?>
  33.  
and the result I get is file1hosname,file1physicaladd,file1'sIp,file2'shos tname.........
Now actually , I want to store the result into one text file or execel file.(or database)...I need a way in which i can store the value of (e.g)
array1[0] = file1's hostname
array1[1]= file2's hostname
....
array2[0] = file1's IP
array2[1]= file2's Ip ....

how can i do so...?
Thanks
Jul 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Earl Teigrob | last post by:
I am considering writing a Class that Selects, Adds, Updates and Deletes Nodes in an XML File but do not what to reinvent the wheel. (See XML file below) That data format would emulate records...
8
by: Bob | last post by:
I need to create a Regex to extract all strings (including quotations) from a C# or C++ source file. After being unsuccessful myself, I found this sample on the internet: ...
4
by: zlj0000 | last post by:
//迷宫问题 #include<stdio.h> #include<malloc.h> #define sqstack S #define STACK_INIT_SIZE 100 #define STACKINCREMENT 10 struct zuobiao{ int i;
8
by: hiro | last post by:
Hi there, I'm very new to python, the problem I need to solve is whats the "best/ simplest/cleanest" way to read in multiple files (ascii), do stuff to them, and write them out(ascii). --...
14
by: Jim Langston | last post by:
The output of the following program is: 1.#INF 1 But: 1.#INF 1.#INF was expected and desired. How can I read a value of infinity from a stream?
9
by: TommyC | last post by:
Hi guys, First, I detect coordinates for left and right corners of a mouth in Corners.c and saved in struct Coordinate for 72 images. How can I able to link it to another C file, let's say try5.c...
5
by: pramodkh | last post by:
Hi All I am trying to match a pattern in a file and insert a line. If the pattern matches then insert a line before the matching pattern line. for example, I have the following content in a...
2
by: Zetten | last post by:
I've got a script which basically goes line by line through an external file, and hands it to the screen in a slightly parsed form. I'd like to apply another bit of parsing to what's coming in...
0
by: grego9 | last post by:
I have a bit of visual basic code in an excel spreadsheet that I need some help with. I am attempting to search a file called TO Cancellations2.xls for counterparty names and for each counterparty...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.