file compare and make a new file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting file compare and make a new file
# 8  
Old 05-05-2009
Hi Devaraj,

It did not work...there is some syntax error.....I copied it from console so full error message is not appearing here but I tried many time and tried to modify as well but no clue...
# 9  
Old 05-05-2009
https://www.unix.com/shell-programmin...#post302298986 Should get you started. If you follow the basic logic, the script loads the files into an array and dumps it back out again.


You will need to modify the script.
  1. You will need to add the logic for doing the comparison of x2==y3 and then dump the rest of the information.
  2. The awk script I wrote directly stores a single item only. You will have to modify it for the full array.
# 10  
Old 05-06-2009
Quote:
Originally Posted by yale_work
Hi Devaraj,

It did not work...there is some syntax error.....I copied it from console so full error message is not appearing here but I tried many time and tried to modify as well but no clue...
Did you try using nawk?
# 11  
Old 05-06-2009
Thanks...

I am using the following...you have to guide me a bit on this....

awk -F "|" '{print $1}' file1|xargs -i grep {} file2|awk '{print$1}' file2

say file1 is:
12345,X,Y
file2 is:
12345,TEST1

I am doing a comparision on column1....if matches print file1...how can I modify this command to get file1 and then the second column of matched record.....for the above example....12345,X,Y,TEST1
# 12  
Old 05-06-2009
Please help me in fixing the following command:

awk -F "|" 'FNR==NR {a[$1]++; next} {print $0,a[$1]}' file1 file2 >>file3

File1
3308100100|C|20.83|21.87|22.91|04/APR/2009|2009|02|MAR
0102110500|C|5.01|5.26|5.51|04/APR/2009|2009|02|MAR
3308100100|C|18.74|19.67|20.61|04/APR/2009|2009|02|MAR
0102140200|C|5.07|5.32|5.57|04/APR/2009|2009|02|MAR
3308100100|C|741.50|778.58|815.65|04/APR/2009|2009|02|MAR
0104100400|C|41.26|43.33|45.39|04/APR/2009|2009|02|MAR
0530100300|C|38.26|40.17|42.08|04/APR/2009|2009|02|MAR

file2
3308100100|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
0530100300|Total Markdowns(FT BRAGG MS - SOUTH)
4792999900|Productivity(TRAV AFB)

the file3 should be like this:
3308100100|C|20.83|21.87|22.91|04/APR/2009|2009|02|MAR|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
3308100100|C|18.74|19.67|20.61|04/APR/2009|2009|02|MAR|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
3308100100|C|741.50|778.58|815.65|04/APR/2009|2009|02|MAR|Store Inventory Turns Without Gas(FT LEONARD WOOD MS)
0530100300|C|38.26|40.17|42.08|04/APR/2009|2009|02|MAR|Total Markdowns(FT BRAGG MS - SOUTH)


you can see comparision is being done on column 1 of both the files...if column1 of file 1 matches with column 1 of file2 then we need to append column 2 of file 2 in the end of matching rows from file1............please let me know if it is possible or not?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

3. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

4. Shell Programming and Scripting

How to make multiple small file out of a single file?

Hi, I have a file that consist of around six million line, now the task is to divide this file into 12 small file so that each file would have half a million lines in it. Thanks. (3 Replies)
Discussion started by: mukulverma2408
3 Replies

5. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

6. Shell Programming and Scripting

make the name of file and fetch few things from log file

Hello All, I am working on a script where I need to fetch the value from a log file and log file creates with different name but few thing are common DEV_INFOMGT161_MULTI_PTC_BLD01.Stage_All_to_stp2perf1.042312114644.log STP_12_02_01_00_RC01.Stage_stp-domain_to_stp2perf2.042312041739.log ... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

7. Shell Programming and Scripting

how to make my own file as a running log file in bash

Hi, I have written a small script from that iam appending the output to a file.If multiple users invoke the same script or if i invoke the same script n number of times (using &), the output file(ZZ/OUT) contains messup information. #!/bin/bash # echo "Hello" >> /tmp/ZZ/OUT sleep 10 echo... (4 Replies)
Discussion started by: blrguest
4 Replies

8. Programming

makeutility: how to get the make-file name inside of the make-file?

How I can get the current make-file name in a make-file So, if I run make with specified file:make -f target.mak is it possible to have the 'target' inside of the that 'target.mak' from the file name? (2 Replies)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

Paste content of a file to another file and make it as columned

Pls help me on this. I have to 2 files like shown below: File 1 TAIJM AXPKIM BEMGW File 2 PXMPA JYGE IMJP What i want to do is to paste both file to a new file on thir format: File 3 TAIJM PXMPA AXPKIM JYGE BEMGW IMJP I tried cat and print, but it doesn't work. Cn... (6 Replies)
Discussion started by: kingpeejay
6 Replies

10. Shell Programming and Scripting

compare two files and make 1st file same as 2nd file

I am trying to compare two file and make changes where ever its different. for example: Contents of file1 IP=192.165.89.11 NM=255.255.0.0 GW=192.165.89.1 Contents of file2 IP=192.165.89.11 NM=255.255.255.255 GW=192.165.89.1 NOTE HERE THAT NM IS DIFFERENT So i want the changes... (6 Replies)
Discussion started by: pradeepreddy
6 Replies
Login or Register to Ask a Question