Perl search csv fileA where two strings exist on another csv fileB


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl search csv fileA where two strings exist on another csv fileB
# 8  
Old 04-13-2012
Ok. Now I understand.

Try this version (change paths to your particular case):
Code:
$ cat script.pl
use warnings;
use strict;

push @ARGV, qw(
        ./FileA.log
        ./FileB.log
);

#die qq[Usage: perl $0 <fileA> <fileB>\n] unless @ARGV == 2;

my $file_in_process = 1;
my %fileA;

while ( <> ) {
        next if m/\A\s*\Z/;
        chomp;
        my @f = split /\s*,\s*/;

        if ( $file_in_process == 1 ) {
                next unless @f == 2;
                push @{ $fileA{ $f[0] } }, $f[1];
                next;
        }

        if ( exists $fileA{ $f[2] } and grep { $f[5] =~ m/$_/ } @{ $fileA{ $f[2] } } ) {
                printf qq[%s\n], $_;
        }
}
continue {
        if ( eof ) {
                ++$file_in_process;
        }
}
$ perl script.pl
Uk, London, Application, datetime, LaterDateTime, Today This occured blah and I care

This User Gave Thanks to birei For This Post:
# 9  
Old 04-13-2012
Thanks, that worked a treat - You are a Legend!

---------- Post updated at 12:05 PM ---------- Previous update was at 10:47 AM ----------

I should contact the queen for your knighthood!Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep from FileA, search in FileB, edit FileC > Output

Hello, Similar question to my previous posts. I am sorry for the trouble... Just checked my old threads but I can not implement any solution into this case.. My aim is to grab each line in fileA, check it in fileB and merge with fileC (tab separated) in corresponding line as given below: FileA:... (2 Replies)
Discussion started by: baris35
2 Replies

2. Shell Programming and Scripting

Read in search strings from text file, search for string in second text file and output to CSV

Hi guys, I have a text file named file1.txt that is formatted like this: 001 , ID , 20000 002 , Name , Brandon 003 , Phone_Number , 616-234-1999 004 , SSNumber , 234-23-234 005 , Model , Toyota 007 , Engine ,V8 008 , GPS , OFF and I have file2.txt formatted like this: ... (2 Replies)
Discussion started by: An0mander
2 Replies

3. Shell Programming and Scripting

awk read column csv and search in other csv

hi, someone to know how can i read a specific column of csv file and search the value in other csv columns if exist the value in the second csv copy entire row with all field in a new csv file. i suppose that its possible using awk but i m not expertise thanks in advance (8 Replies)
Discussion started by: giankan
8 Replies

4. Shell Programming and Scripting

CSV to SQL insert: Awk for strings with multiple lines in csv

Hi Fellows, I have been struggling to fix an issue in csv records to compose sql statements and have been really losing sleep over it. Here is the problem: I have csv files in the following pipe-delimited format: Column1|Column2|Column3|Column4|NEWLINE Address Type|some descriptive... (4 Replies)
Discussion started by: khayal
4 Replies

5. Shell Programming and Scripting

Extract strings from multiple lines into one csv file

Hi all, Please go through my requirement. I have a log file in the location /opt/WebSphere61/AppServer/profiles/EMQbatchprofile/logs/EMQbatch This file contains the follwing pattern data <af type="tenured" id="42" timestamp="May 14 13:44:13 2011" intervalms="955.624"> <minimum... (8 Replies)
Discussion started by: satish.vampire
8 Replies

6. Shell Programming and Scripting

Comparing Strings in 2 .csv/txt files?

EDIT: My problems have been solved thanks to the help of bartus11 and pravin27 This code is just to help me learn. It serves no purpose other than that. Here's a sample csv that I'm working with - #listofpeeps.csv Jackie Chan,1954,M Chuck Norris,1930,M Bruce Lee,1940,M This code is... (13 Replies)
Discussion started by: chickeneaterguy
13 Replies

7. Shell Programming and Scripting

extract strings from file and display in csv format

Hello All, I have a file whose data looks something like this I want to extract just the id, name and city fields in a csv format and sort them by id. Output should look like this. 1,psi,zzz 2,beta,pqr 3,theta,xyz 4,alpha,abc 5,gamma,jkl (12 Replies)
Discussion started by: grajp002
12 Replies

8. Shell Programming and Scripting

Copying lines from fileA if they start by a word from fileB

Hi I'm in the need of a script that basically takes two files and generates a 3rd. It reads from fileA and fileB and copies lines from fileA if they start by a word of fileB. for example fileA The dog is beautful Where is your cat Why are you sad? Help me! fileB The Where tree dog... (4 Replies)
Discussion started by: FrancoisCN
4 Replies

9. Shell Programming and Scripting

Replacing strings in csv file.

Hi, I have a problem.. 1) I have a file that contains the lines as below : VRF-TM_DummyLab/mse02.lab,mse02.lab,ge-2/0/7.222 VRF-EMS_HUAWEI_MSAN_208/mse01.lab,mse01.lab,xe-1/0/0.208 2) I need a method to read this file, line by line from :... (5 Replies)
Discussion started by: msafwan82
5 Replies

10. Shell Programming and Scripting

Replacing strings in a log file and saves as a new csv

Hello Im new here.I need to replace strings and change it into csv format, or at least saves the file as csv if that would work :p. Heres an example of my scenario 1) I have a log file, named abc.log, and its like a txt based file anyway, and the content looks like this ... (2 Replies)
Discussion started by: tententen
2 Replies
Login or Register to Ask a Question