Hello,
I am currently attempting to learn perl and would like some help or examples to get me out of this rut. I have three files, File1 is local while File2-1 is accessed via ssh host2-1 and File2-2 accessed via ssh host2-2.
I need to search File1 for a keyword, when this keyword is found on any number of lines it will take $commonnumber in that line then it will need will to look in to both File2-1 and File2-2 for this same number and print out the $uniquenumber associated. File2-1 and File2-2 are not identicle, so it may find $uniquenumber on either or both File2-1 or File2-2.
Lets say the information in each file is in the following format:
File1:
$message, $commonnumber
File2-1:
$uniquenumber, $commonnumber
File2-2:
$uniquenumber, $commonnumber
Now I can search the local file, find the line I want, then output it in the form I would like but I cannot figure out howto look in File2-1 and File2-2 and grab $uniquenumber. I tried using the following without any success to get this information:
my @whatever01=system('ssh somehost "grep $commonnumber File2-2"');
This is what I have so far, that only prints info i want in File1, I have no idea where to go from here to print info from two different files to the terminal screen.
This info is probley pointless for me to post here but oh well.
#!/usr/bin/perl -w
use strict;
open(File1, "File1");
while (<File1>) {
if (/@ARGV/) {
my @atlmmg01=split(/:/);
my $commonnumber=@atlmmg01[17];
print "-----------------------------------------------
+----------
----\n";
print "@atlmmg01[2]\n";
print "@atlmmg01[17,18]\n";
print "@atlmmg01[26]\n";
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.