File comparision with AWK / SED


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File comparision with AWK / SED
# 1  
Old 03-25-2011
File comparision with AWK / SED

Hi all

I need to compare two separate product lists that are changed weekly. New products are added, old products are removed and prices change.

I have found various Windows programs that do this function but it's not as clean as I like and just wondered if there was a simpler way with something like AWK or SED

Both files come in a tab delimited format, although I can easily modify this. The samples below show 7 columns:

Name
Category
Quantity
Manufacturer
Image
Price
Weight


File 1
Code:
Castillo d'Canena Extra Virgin Arbequina Olive Oil (250ml)    8            10000        Castillo    data/products/tins_jars_and_cooking/174510.jpg        6.49                0.250
Castillo d'Canena Extra Virgin Picual Olive Oil (250ml)    8            10000        Castillo    data/products/tins_jars_and_cooking/173834.jpg        6.49                0.250
Farchioni Il Casolare Olive Oil Extra Virgin (1L)    8            10000        Farchioni    data/products/tins_jars_and_cooking/004748.jpg        9.09                1.000


File 2
Code:
Castillo d'Canena Extra Virgin Arbequina Olive Oil (250ml)    8            10000        Castillo    data/products/tins_jars_and_cooking/174510.jpg        7.49                0.250
Castillo d'Canena Extra Virgin Picual Olive Oil (250ml)    8            10000        Castillo    data/products/tins_jars_and_cooking/173834.jpg        6.49                0.250
Filippo Berio Extra Virgin Olive Oil (250ml)    8            10000        Filippo Berio    data/products/tins_jars_and_cooking/004715.jpg        1.83                0.250
Filippo Berio Extra Virgin Olive Oil (500ml)    8            10000        Filippo Berio    data/products/tins_jars_and_cooking/004406.jpg        3.87                0.500


As you can see, the following are:

1. The 3rd product from File 1 has now gone
2. The price of the 1st product from File 1 has increased to 7.49
3. Two new Filippo products from File 2 have been added

I need a produce a merged file which has the new prices for each product, the old products taken out and the new products added. Is this possible easily with AWK / SED or easier sticking with a Windows product?

Any help kindly appreciated.

Last edited by Franklin52; 03-25-2011 at 10:19 AM.. Reason: Please use code tags
# 2  
Old 03-25-2011
Too many information missing :
What is you initial file ?
What is are the criteria for adding, deleting, or modifying the product ? (a file instructing for such modification should have a clear instructions' convention definition)
Your current example is ambiguous as is so please give a full example of
1) initial file
2) instruction file
3) expected result file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk comparision between 2 files and substitution in third

Hi All, I have two files in the following format. File 1 : 1044|1|20121031|2910039.4|MR|201210|G1044|E 1082|2|20121031|1664662.84|MR|201210|G1082|E 1696|3|20121031|190801.5|MR|201210|G1696|E 1824|4|20121031|196350|MR|201210|G1824|E 1900|5|20121031|221447.8|MR|201210|G1900|E File 2 :... (7 Replies)
Discussion started by: nua7
7 Replies

2. Shell Programming and Scripting

Awk comparision

Hi Everyone I am new to Unix shell scripting Can anyone please explain me in detail how this command works awk -F@ 'NR==FNR{A=$2;next}$3 in A{$3=A}1' file2 file1 The above command I got it from this forum, but unable to implement it as I am not getting how this works:mad: I... (3 Replies)
Discussion started by: Vijay90
3 Replies

3. Shell Programming and Scripting

awk: string followed by tab comparision

Hi all, Currently i am using if( $0~/ NOT / && $0~/ NULL /) { ................. } to check if the input record contains "NOT" and "NULL". But in some cases "NOT" and "NULL" are preceded and followed by tab. How do i find compare for these fields as well? (3 Replies)
Discussion started by: ysvsr1
3 Replies

4. Shell Programming and Scripting

File Comparision

Hi All, I want to write a script which will compare two files and tell me if the files are different. Actually my files will be same but order of lines will be different,so diff is not working. I have written a script to do this:- while read line; do cnt=`grep -i $line... (6 Replies)
Discussion started by: prasson_ibm
6 Replies

5. Shell Programming and Scripting

Range of records using comparision \awk

Hi Gurus, I have to fetch the records from a logs as per the time stamp . I am comfortable to use awk and sed in the script . But the logic to fetch the records as per comparison is the problem. $cat my_log.log <Jul 30, 2010 7:01:12 AM EEST> <Error> <WebLogicServer> <Jul 30, 2010 8:04:12 AM... (3 Replies)
Discussion started by: posix
3 Replies

6. Shell Programming and Scripting

File comparision

Hi All I have to files cat a.txt AAA BBB CCC DDD and cat b.txt AAA CCC EEE i want to compare these two files and o/p should have content of file a.txt which is not in file b.txt c.txt BBB DDD Please help me (3 Replies)
Discussion started by: aaysa123
3 Replies

7. Shell Programming and Scripting

File comparision

Hi All I have to files cat a.txt AAA BBB CCC DDD and cat b.txt AAA CCC EEE i want to compare these two files and o/p should have content of file a.txt which is not in file b.txt c.txt BBB DDD Please help me (1 Reply)
Discussion started by: aaysa123
1 Replies

8. Shell Programming and Scripting

File comparision

HI, I would like to know how to compare two files and replace non-matching lines with "_" . I can get non-mathing lines with grep -v -f file1 file2 i just want to knw how to display 'file2' with non-matching lines from 'file1' replaced by "_" for exmaple file1: a b c d ... (2 Replies)
Discussion started by: maddy81
2 Replies

9. Shell Programming and Scripting

file size comparision local file and remote file

Hi, I have written a script which would FTP a dump file to the FTP server and log the whole activity into a file. to confirm the success of the file copy i grep for "226 file receive OK" and then send out an email saying success. Now i want to make sure the bytes of the local file and... (4 Replies)
Discussion started by: dba.admin2008
4 Replies

10. UNIX for Dummies Questions & Answers

Number comparision in AWK

Hi, I have a file like this. "2006","10",25,"U","1129","32","C",0,0,0,0,0,0,0,0,0,0,0,0,352,16,4,0,0,0,0,0,"80",,1 "2006","11",25,"U","1148","32","C",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"80",,2 "2006","14",25,"U","1149","10","C",0,0,0,0,0,0,0,0,0,0,0,0,560,12,0,0,0,0,0,0,"80",,3... (1 Reply)
Discussion started by: vskr72
1 Replies
Login or Register to Ask a Question