Programming :: Comparing Two Files In Perl ?
Oct 9, 2009
I would like to ask opinion from perl experts.
I want to compare 2 files and show the differences in a text file.
For example, if i open File A an B in notepad
File A:
File B:
Quote:
line3 is missing in File B
So if I did a File compare (line by line), the differences will be in line3, line4, line5, line 6.
But I dont want it to be like that.
I want it to be like this
Quote:
Can Text:: Diff able to perform the work.
View 1 Replies
ADVERTISEMENT
May 7, 2011
I have two files
Code:
we have to consider here $5 , $6 , $7 for our search
file2.txt
Code:
Here we should take only $2 for comparison. As you can most of the $2 field records has value and some do not have value.
Question:I want to take the fields $5 , $6 , $7 from file 1 and compare it with $2 field from file 2. and the rsult should be like this:
Code:
The final output will look like this
Actual file1.txt (before running the code)
Code:
FIle1.txt after running the above said condition
Code:
So the field $5 , $6 , $7 should get replaced from the matched valued of $1(file1)
View 3 Replies
View Related
Nov 30, 2010
I have two text files i want to compare the differances between but i dont wnat all of them, there is only about 30lines of relvent text i want to compare.
View 10 Replies
View Related
Apr 13, 2011
I have 2 very long files which are quite similar:
file1.csv:
Code:
file2.csv:
Code:
I need this output:
Code:
explanation:
If the fields 3 (serie) and 4 (modello) are identical, the lines of the 2 files should be "added":
Code:
If the fields 3 (serie) and 4 (modello) are different, just print the line of both files:
Code:
Is there a way to do this without reading the (huge) files with a "while read line" loop?
View 14 Replies
View Related
Jul 24, 2010
How do I download a file to a specified location on disk in Perl?I tried doing a few web searches but suprisingly couldn't find anything.
View 4 Replies
View Related
Jul 8, 2009
I need to count files in a dir which were updated yesterday.
ls -lth | grep -i 'Jul 7' | wc -l
The dir holds files of last 15 days and total count is as 2067476. Is it efficient to count the files using perl? I have developed the following perl script making use of system().
Code:
#!/usr/bin/perl
@months = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
($sec,$min,$hour,$monthday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
[code]....
View 12 Replies
View Related
Aug 23, 2010
I am looking for some suggestions if possible, regarding processing the files using perl script. Scenario is I have a location where new files will be added always. I need to process these files for some validation. I wrote a perl script to do this and I thought I can rename the files once they are processed in that way I dont process the same files again. But now I can't rename the files due to some restrictions. Second thought, to process them based on date stamp but as my perlscript is being automated and runs every one hour to process the files I can't go by date stamp.
View 5 Replies
View Related
Mar 8, 2010
I want to compare the following two tab-delimited .txt files (both were subsets of the original files) by comparing Columns 3 and 4 simultaneously. It is easy to compare C3 because both C3s are just numbers. But how to compare C4s?Basically, in File1, "G,G" = G in File2, "C,C" = C in File2, "A,A" = A in File2, "T,T"= T in File2.In File2, A/T in Column4 just equals "A,T" or "T,A" in Column4 of File1. C/T in Column4 just equals "C,T" or "T,C" in Column4 of File1, and etc.
File1:
C1C2 C3C4
ih509rs12345467244750"G,G"
ih499rs6049687244911"C,C"
ih508- 7244977"A,A"
[code]....
View 2 Replies
View Related
Dec 20, 2010
So this is my code:
Code:
Modification of code I found here. It works, but I don't really know why.
Q1: Why is each filter hit counted only when the conditional is not true?
Q2: I've tried taking the file type, (.old), and put it into a variable for better usability, but then the script fails.
View 14 Replies
View Related
Aug 26, 2010
I am new to perl scripting and wrote a perl script to read the directories and files and count the no of files in each directory and generate a log file. The problem is it is not printing anything to the log file. I am copying the script below.
!/usr/local/bin/perl
$dir= 'c:My ProjectsPerl ScriptsNew Folder' ;
$directory_count = 0;
$file_count=0;
[code].....
View 14 Replies
View Related
Mar 21, 2010
I need write a script that can compare multiple input files and output a file. The basic idea is:1: All my input files are in the same format2: I want to find in-common lines (in-common 1) from some of my input files (e.g., input1, 2 an 3), and find in-common lines (in-common 2) from the rest of my input files (e.g., input 4,5,6,7). And then, compare in-common1 and in-common2 and remove any overlap from in-common 1.3: Output the remaining in-common 1 file after removing any of its overlap with in-common 2I know how to write this script by putting all the filenames in one script and compare them. But the thing is, if I have more input files, such as 100, it might not be that efficient to write all filenames in one script and compare them.
I am wondering if there is any way to do such as:1: put all input filenames in a text file (file1)2: write a script3: Everytime, when I run this script, it will read in file1 directly no matter how many input files I have, give an output.I want this because I will have more and more input files and I don't wanna add multiple lines in the script just for reading the new inputfiles and compare them with the previous files. So, I guess this is something related to making my script a package or standardize it and make it easy to use in the future no matter how many input files I will have.
View 5 Replies
View Related
Mar 20, 2010
I am fairly new to Linux and was needing some help on a comparing more than 2 files. I am try to come up with something that would compare at least 10+ different files to a master file and give me an output of what is missing.
Example would be: a.txt, b.txt, c.txt, d.txt compare each of them to the master.txt file, than output the missing text for each file into new file.
I came across comm and diff commands, am I looking in the right place or is there a much easier way of doing this?
View 2 Replies
View Related
Jul 12, 2011
I have a file1:
Code:
$ cat PF(1).out
Tmp39 PF10271.3 423 ENSP00000326063 488 1.2e-201 41-478
Tmp39 PF10271.3 423 ENSP00000338165 492 1.9e-200 46-479
[code].....
View 14 Replies
View Related
Jul 7, 2010
What's the command for comparing files? I think I've used it before, but can't remember it.
View 3 Replies
View Related
Sep 19, 2010
If I have a variable, say xvar, which can take both string and integer value and I want to perform an operation in following 2 conditions:1. Either xvar is null2. xvar equals 2[ -z "$xvar" ] || [ $xvar -eq 2 ] && <some-code>Doesn't seem to work if xvar takes string valuesI know that since I have no restriction on xvar, I can get away with string comparison in second test too, ie[ -z "$xvar" ] || [ "$xvar" = "2" ] && <some-code>
But, 'Sams teach yourself shell script in 24 hrs' says that [ expr1 -eq expr2 ], if either is string, it assumes 0 valueIs it true
View 5 Replies
View Related
Nov 5, 2010
Is there a way, besides writing a PERL program, to read each line one by one in file A and tell if this line also exists in file B? Can this be done via a shell script?
View 6 Replies
View Related
Sep 18, 2010
I wish to compare all the files in a directory....comparing is by content. And same files should be printed...
echo "program : $0"
cd $1
for a in *
do
[code]....
This logic did not give the correct result...
View 5 Replies
View Related
Sep 2, 2010
I want to compare two files and display values unique to file1. I tried using comm but it did not give me useful outputs.
comm -2 -3 file1 file2 does not work
Similar threads provide matched content. What I am looking for is unique content.
View 9 Replies
View Related
Jul 26, 2010
Iam having the following two linux files.
[Code]...
Now i want the following out puts
1. similar nos in both the file 1 and file 2 > output= File 3;
2. In file 1, but not in file 2 > out put= file 4;
3. In file 2, but not in file 1 > output = file 5;
The command sdiff is giving output with symbols > < | etc, and the such output file is not clear and ready to print. I want to print directly the output files. AND ALSO TELL ME WHERE I HAVE TO WRITE AWK PROGRAMS AND HOW TO RUN IT.
View 5 Replies
View Related
Apr 1, 2011
have a simple script for comparing two directories. I want to list all differences between this directories.
here is my function for compare:
function comp
{
for i in $1/*; do
if [ ! -e "$2/${i##*/}" ]; then
echo $i
[Code]....
in my script these two files are equal(my script ignored last time modified)
View 5 Replies
View Related
Mar 25, 2011
I want to compare 2 IP addresses, so that I may compare which is more/less "specific" or "restricted" than the other. So is there any function/library that may help in doing this comparison in C (on Ubuntu 10.10)?
View 1 Replies
View Related
Oct 11, 2010
I need a script which can format the below text file which contains comments
Code:
Code:
Output should be:
Code:
Code:
Script should compare the column name and paste the output in above said manner.
View 13 Replies
View Related
May 16, 2010
I have two arrays of data, called data1.dat and data2.dat. each contains 60 data. What I want to do is to compare the data in each file and write the counting into bins. It goes like this. First, take the first data in data1.dat file and compare with the 60 data in data2.dat file. If there is any data which is same with the data in data1.dat then it count in bin. The total bins are also 60. Next it goes to the second data in data1.dat and compare with all the 60 data in data2.dat. If there is any data same then it add in second bin. And it repeats to all the data in data1.dat
View 3 Replies
View Related
Jun 13, 2010
I've got an interesting challenge for the shell scripting wizards here. I've got a mySQL dump of three files for my amarok database with the intention of copying some files to my media server (cover art) so that I can keep the server the server and not rely on my local machine.
Step 1: Identify any cover art files on my local machine.
I did this with:
Code:
mysql -u amarok -p amarok -e "SELECT * FROM images WHERE path like '%.kde%'" > cover_art.txt
Output looks like this:
[Code]....
What I have here now is the ENTIRE album list in my collection -- and something to compare the IDs in Step 1 against. I'm going to stop here and will update the thread as I get past this stumbling block. "ID" in cover_art.txt = "image" in albums.txt... straightforward enough, right?
So the question is this: how do I create a simple shell script that will loop through the IDs in cover_art.txt (i.e. characters 0 -> 4 -- it will always be a 4 digit ID) and then search for that ID in the Albums.txt file.
View 3 Replies
View Related
Jan 23, 2010
I've got a strange bug that I cannot figure out how to solve. Here is the function.
Code:
int getnexttab(char input[], int index, int length)
{
[code]....
View 14 Replies
View Related
Nov 8, 2009
Two files contain:
file1:
cat
dog
fish
hamster
file2:
cat
fish
ferret
dog
How do you change the case of the letters in file1.txt to uppercase and compare with file2 all in one command?
View 2 Replies
View Related
Sep 17, 2009
Im trying to compare two files and I only want to display the user names that are in the first file and not the second.
So I have one file named final.txt (which contains every user name and only the user names in a list no other information)
Then I have another file Over1.txt (which only contains certain users that have different permissions This file is also setup differently with the user name and some information about the user after the user name.
I need a way to compare final.txt to over1.txt so that I will only display the names that are in final.txt but not Over1.txt
Ive tried using diff and comm but just cant seem to get it two work correctly. Im not sure if im missing a option or what.
View 5 Replies
View Related
Jun 9, 2009
I have been messing with diff and grep for 2 days now without result
I am trying to match a file consisting of words to many separate other wordfiles in a specific directory. one by one.
What i want the script to do is to report how many matching words my main file has with every file in the directory, each in turn
setup:
Each of em are plain text files with 1 word per line
Output should be something like:
SCRIPT REPORT:
View 8 Replies
View Related
Jul 21, 2010
Where is the perl module for programming with sockets?
View 4 Replies
View Related
May 9, 2010
I just downloaded Tk-804.028 and try to install it (according to the README.linux) but I get:
> perl Makefile.PL
/opt/ActivePerl-5.10/bin/perl-static is installed in /opt/ActivePerl-5.10/lib okay
PPM for perl5.010001
Test Compiling config/perlrx.c
Test Compiling config/pmop.c
Test Compiling config/pregcomp2.c
[code]...
View 5 Replies
View Related