compare two files with specific rules when comparing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting compare two files with specific rules when comparing
# 15  
Old 09-07-2008
Thanks! A little research and I discovered the answer Smilie.

I changed 'file1 file2' at the end of the script to '$1 $2' and then I can pass in the file name at command line...this is a great learning experience for me. I feel I'm learning a lot here. Thanks everyone for helping me out !
# 16  
Old 09-08-2008
Hi, I'm not sure how to change the output so it would include

1:XXXXXX-XXXXXX

where the XXXXX would be the number for the specific row that it outputs.
# 17  
Old 09-08-2008
Not sure what you mean exactly? You just want to insert : and - as field separators? Or you want to include the line numbers from the input file or files?
# 18  
Old 09-08-2008
Quote:
Originally Posted by Annihilannic
Not sure what you mean exactly? You just want to insert : and - as field separators? Or you want to include the line numbers from the input file or files?
Sorry, so for example, the output i would like should be this:


Code:
file4 1:91625115-91626003 overlaps with 1:91625106-91626002
file4 1:121185385-121187221 overlaps with 1:121185385-121187221
file4 1:143785958-143787823 overlaps with 1:143786446-143787519
file4 1:154452584-154453545 overlaps with 1:154452584-154453547
1:204875171-204876073

# 19  
Old 09-08-2008
You can just append strings and variables to print them consecutively like this:

Code:
print $1 ":" $2 "-" $3

If you use commas like I did the default output field separator (OFS variable) is used to separate the parameters that are printed.
# 20  
Old 09-09-2008
I see. excellent insight. Learning by example I think is so much easier for me than reading the man file. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to update field based on a specific set of rules

In the perl below, which does execute, I am having trouble with the else in Rule 3. The digit in f{8} is extracted and used to update f accordinly along with the value in f. There can be either - * or + before the number that is extracted but the same logic applies, that is if the value is greater... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Linux

Comparing specific columns between two files

Dear All, I have two files. File-A having 5 columns and File-B having 2 columns. I want to match 4th column of file-A with both columns of file-B and print all contents of file-A + the matching lines of file-B as output. file-A 30.00 12 gi|49483390|ref|YP_040614.1| ... (5 Replies)
Discussion started by: Syeda Sumayya
5 Replies

3. Proxy Server

IPtable rules for DNS/http/https traffic for specific hosts only, not working.

Hi there, I have a VPS and am working on a little side project for myself and friend which is a DNS proxy. Everything was great till recently. My VPS IP has been detected by some botnet or something, and I believe SMURF attacks are occuring. The VPS provider keeps shutting down my VPS... (3 Replies)
Discussion started by: phi0x
3 Replies

4. UNIX for Dummies Questions & Answers

Comparing to specific line in file bash script

Hi, I have a value stored in x and I need to compare it to the numbers in every other line of a file. The file contains alternating lines of numbers and letters: aaaa1111 AAAAAAAA bbbb2222 BBBBBBBB cccc3333 CCCCCCCC I need to compare x to the numbers in every other line without the... (2 Replies)
Discussion started by: ShiGua
2 Replies

5. Shell Programming and Scripting

awk compare specific columns from 2 files, print new file

Hello. I have two files. FILE1 was extracted from FILE2 and modified thanks to help from this post. Now I need to replace the extracted, modified lines into the original file (FILE2) to produce the FILE3. FILE1 1466 55.27433 14.72050 -2.52E+03 3.00E-01 1.05E+04 2.57E+04 1467 55.27433... (1 Reply)
Discussion started by: jm4smtddd
1 Replies

6. Shell Programming and Scripting

Help with allocated text content based on specific rules...

Input file format: /tag="ABL" /note="abl homolog 2 /tag="ABLIM1" /note="actin binding LIM 1 /tag="ABP1" /note="amiloride binding protein 1 (amine oxidase (copper- containing)) /tag="ABR" /note="active BCR-related /tag="AC003042.1" /note="SDR family member 11 precursor . . . (4 Replies)
Discussion started by: perl_beginner
4 Replies

7. UNIX for Dummies Questions & Answers

Comparing a number in a text file with a specific value

My project is to get a temperature reading from a refridgerator every 2 minutes and check to see if the door has been left open. I don't yet have the mastery of Linux, being a complete noob, but I reckon I need a text file with the latest temperature reading in it. This I've managed to do by... (2 Replies)
Discussion started by: Fitch
2 Replies

8. Shell Programming and Scripting

Compare specific columns between two files having different layouts

Hi, My requirement is that I need to compare two files. For example : The first file will be having 15 columns and the second file will be having just 10 columns. Example : File1 : abcd,abrd,fun,D000,$15,$236,$217,$200,$200,$200... (3 Replies)
Discussion started by: gpsridhar
3 Replies

9. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

10. UNIX for Dummies Questions & Answers

How to compare 2 files & get specific value & replace it in other file.

Hiiii Friends I have 2 files with huge data. I want to compare this 2 files & if they hav same set of vales in specific rows & columns i need to get that value from one file & replace it in other. For example: I have few set data of both files here: a.dat: PDE-W 2009 12 16 5 29 11.11 ... (10 Replies)
Discussion started by: reva
10 Replies
Login or Register to Ask a Question