How to fetch matched records from files between two different directory?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to fetch matched records from files between two different directory?
# 1  
Old 01-26-2016
How to fetch matched records from files between two different directory?

[Hi All,
I am new to Unix and trying to find matched records between two files and from different directories. Finally want to store the output in excel file. I have tried the query like below. But it is thrown error. Kindly help me how to find the matched records.

Code:
awk 'NR==FNR{arr[$0];next} $0 in arr' /tmp/Data_mismatch.sh /prd/HK/ACCTCARD_20160115.txt

Moderator's Comments:
Mod Comment edit by bakunin: seems that one CODE-tag got lost somewhere. i corrected that, but please check your posts more carefully. Thank you.

Last edited by Don Cragun; 01-27-2016 at 04:42 AM.. Reason: Remove extraneous closing square bracket.
# 2  
Old 01-26-2016
Please use code tags as required by forum rules!

And, be way more specific. What be the error? What's the files' structures? What's the desired output structure? With awk, you can't create EXCEL files; the best/nearest you can get is csv structure.
# 3  
Old 01-26-2016
Thanks for your reply. Have two source files and both are from different directories. Please find the file format below.

Code:
File1: Data_MisMatch.txt Directory:/tmp

Customer No:
---------------
256789
345780
908125

File 2: ACCTCARD_20160115.txt Directory: /Prd/HK
Column1,Column2,Column3
1,256789,4EXY234
2,789012,34iyq901
3,908125,2345we1

As per the above data, 2 records are matching between Data_MisMatch.txt and ACCTCARD.txt source files.

I want store only 2nd and 3rd columns from the matched records in ACCTCARD.txt source file.

Hope!I explained my scenario. Kindly help me how to get the matched data between two files. Your help is much appreciated.
# 4  
Old 01-26-2016
Please, copy and paste and give it a try:
Code:
awk -F, 'FNR==NR{m[$1]; next} $2 in m{print $2,$3}' OFS=, /tmp/Data_MisMatch.txt /Prd/HK/ACCTCARD_20160115.tx

Watch the comas. It will output to the screen the matches.
# 5  
Old 01-27-2016
Have tried like you said. But it did not return any matching value.

Code:
awk -F, 'FNR==NR{m[$1]; next} $2 in m{print $2,$3}' OFS=, /tmp/Data_MisMatch.txt /Prd/HK/ACCTCARD_20160115.txt

Could you help on this?
# 6  
Old 01-27-2016
What operating system are you using?

What shell are you using?

What is the output from the command?:
Code:
od -bc < /tmp/Data_MisMatch.txt

What is the output from the command?:
Code:
head -n 3 /Prd/HK/ACCTCARD_20160115.txt | od -bc

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do i read only last 5 files records from a directory.?

Hello team, I have a directory containing huge number of files. I need to go select last 5 files and read it to do a calculation. Kindly guide, how can i achieve it. Regards, Sadique (13 Replies)
Discussion started by: sadique.manzar
13 Replies

2. Shell Programming and Scripting

Extract Matched Records from XML

Hi All, I have a requirement to extract para in XML file on the basis of another list file having specific parameters. I will extract these para from XML and import in one scheduler tool. file2 <FOLDER DATACENTER="ControlMserver" VERSION="800" PLATFORM="UNIX" FOLDER_NAME="SH_AP_INT_B01"... (3 Replies)
Discussion started by: looney
3 Replies

3. Shell Programming and Scripting

Fetch files based on month

Hi All I have a requirement like below.I have always 12 files got generated in my directory called /xx/out/ abc_2014_10_121.xml abc_2014_09_345.xml abc_2014_08_432.xml abc_2014_07_123.xml abc_2014_06_098.xml abc_2014_05_569.xml abc_2014_04_430.xml abc_2014_03_235.xml abc_2014_02_056.xml... (9 Replies)
Discussion started by: chigurupati.dwh
9 Replies

4. Shell Programming and Scripting

Fetch the last two days directory names and rename them

Hi All, I have below directory structure and from these directories, I would like to fetch the last two days list of directories and append a '0' (zero) to those directories. bash-4.1$ ls -lrt total 32 drwxr-xr-x+ 6 root root 9 Sep 5 01:05 tested-597 drwxr-xr-x+ 6 root root 9 Sep 9... (3 Replies)
Discussion started by: ibad_urs
3 Replies

5. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

6. Programming

c++ program to fetch files in windows from xshell

hey i'm new at this stuff. i need to write a program in windows. which will fetch files from a unix machine using xshell. please help me with this. (4 Replies)
Discussion started by: tan_army810
4 Replies

7. Shell Programming and Scripting

Grep matched records from huge file

111111111100000000001111111111 123232323200000010001114545454 232435424200000000001232131212 342354234301000000002323423443 232435424200000000001232131212 2390898994200000000001238908092 This is the record format. From 11th position to 20th position in a record there are 0's occuring,and... (6 Replies)
Discussion started by: mjkreddy
6 Replies

8. Shell Programming and Scripting

how to fetch substring from records into another file

Hi all, Im stuck in findind solution to ths problem. Please guide me if u have any ideas. I have two files. ===FILE1=== >bi|2138271|geb|AAC15885.1|precursor MRVIAAAMLYLYIVVLAICSVGIQGIDYPSVSFNLAGAKSATWDFLRMPHDLVGEDNKYNDGEPITGNII... (25 Replies)
Discussion started by: smriti_shridhar
25 Replies

9. Shell Programming and Scripting

how to scan a sequential file to fetch some of the records?

Hi I am working on a script which needs to scan a sequential file and fetch the row where 2nd column = 'HUB' Can any one help me with this... Thanks (1 Reply)
Discussion started by: manmeet
1 Replies

10. Shell Programming and Scripting

Column matched in two files

I have two files with multiple columns separated by commas. I want to search one column from the first file in the second file; If there is a matching, will append that matched row to the first file. Let me show an example... (unique values in the search column) First file aa,reg1,bb,cc,dd,ff... (6 Replies)
Discussion started by: lalelle
6 Replies
Login or Register to Ask a Question