Match columns and fetch whatever in front of it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match columns and fetch whatever in front of it
# 1  
Old 11-12-2012
Match columns and fetch whatever in front of it

Hi Solved these kind of issues using these codes But these are not wrking for my attached files can anybody check........

Code:
awk 'NR==FNR{X[$1]++;next}{if(X[$1]){print}}' file1 file2

Code:
awk 'NR==FNR{X[$1]=$0;next}{n=split($1,P," ");sub($1,"",$0);for(i=1;i<=n;i++){if(X[P[i]]){print P[i],$0}}}' file1 FS="\t" file2

Please let me know any changes for my attached files.

I have to find common entries of first columns in bioth files if matches then fetch whatever in front of it in second file.

first file is BDc

second file is BD use

Kindly check
# 2  
Old 11-12-2012
It should be working with second code as far as I checked?
# 3  
Old 11-13-2012
Yes I did check but it was wrking with my other files but not wrking on these ones!
# 4  
Old 11-13-2012
You need to convert your files to Unix format first:
Code:
tr -d '\r' < infile > outfile

# 5  
Old 11-14-2012
Hi

Thanks for reply. it works for above attached files afetr conversion in unix format.

Now it doesnot work for my these files it says error

Code:
bash-3.2$ awk 'NR==FNR{X[$1]=$0;next}{n=split($1,P," ");sub($1,"",$0);for(i=1;i<=n;i++){if(X[P[i]]){print P[i],$0}}}' CDc.txt FS="\t" CDnsn4.txt
awk: (FILENAME=CDnsn4.txt FNR=250) fatal: Invalid range end: /UGT1A[1,3-10]/

There is a name in second file UGT1A[1,3-10] even if I remove it still it doent wrk

dont knw whats the error kindly guide.It nver happens with me though

mani
# 6  
Old 11-14-2012
Can anybody guide for my above question and code it seems simple, But I am in need for this now!!!Smilie
# 7  
Old 11-15-2012
CDc.txt is still in DOS format.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies

2. Shell Programming and Scripting

How to dynamically fetch lines after a match?

Hi Friends, How to fetch current hour data from a log file, given below? I want all lines after the match "Wed Aug 13 16:" I have tried below command, but not working. If I put exact string, then it is working. cat /iscp/user/monitor/ORA_errors |awk '/`date +%h" "%d" "%h`/,printed==999 {... (7 Replies)
Discussion started by: suresh3566
7 Replies

3. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

4. Shell Programming and Scripting

Match first column entries precisely and fetch whatever in front of it

Hi all I have 2 files: first file AABC TTYP JKBH CVBN NHJK KJHM Second file is AABC,XCYU,JUHD Alllele1 GACXT It is approved study TTYP,JKBH Allele2 PPRD It is clinical trial study JKBH Allele2 PPRD ... (5 Replies)
Discussion started by: Priyanka Chopra
5 Replies

5. Shell Programming and Scripting

Find common and fetch what ever in front of it

Hi guys As my previous one is not working now I have a different problem with me one file with entries F2 F3 YUH SUH second fiel several columns like excel sheet (8-9) but my file in text F2 fgf gfhjhjghjghj dhgfhgfh 234324 F3 ... (6 Replies)
Discussion started by: Priyanka Chopra
6 Replies

6. Shell Programming and Scripting

Fetch entries in front of specific word till next word

Hi all I have following file which I have to edit for research purpose file:///tmp/moz-screenshot.png body, div, table, thead, tbody, tfoot, tr, th, td, p { font-family: &quot;Liberation Sans&quot;; font-size: x-small; } Drug: KRP-104 QD Drug: Placebo Drug: Metformin|Drug:... (15 Replies)
Discussion started by: Priyanka Chopra
15 Replies

7. Shell Programming and Scripting

Match words and fetch data in front of it in second column

Hi all, I have 2 files one file contain data like this in one column AST3 GSTY4 JST3 second file containign data like this in 2 columns AST3(PAXXX),GSTY4(PAXXY) it is used in diabetes KST4 it is used in blood... (6 Replies)
Discussion started by: manigrover
6 Replies

8. Shell Programming and Scripting

Match the word or words and fetch the entries

Hi all, I have 7 words Now I have 1 file which contain data in large number of rows and columns and 6th column contain any of these words or may be more than one words among above 7 words: I want script should search for the above mentioned 7 words in the 6th column ... (9 Replies)
Discussion started by: manigrover
9 Replies

9. Shell Programming and Scripting

match sentence and word adn fetch similar words in alist

Hi all, I have ot match sentence list and word list anf fetch similar words in a separate file second file with 2 columns So I want the output shuld be 2 columns like this (3 Replies)
Discussion started by: manigrover
3 Replies

10. Shell Programming and Scripting

Appending the last few columns to the front

Hi consider this as the first line 00010015 MORGAN STANLEY & CO INCORPORATED N 110 INVESTAR 1 0001OT NJ 201-830-5055 01-Jan-1974 00:00:00 1 01-May-2008 00:00:00 05-Jun-2008 13:34:18 0001 - From SMSRun1_GIDQA02 Consider this as the second line 00010015 MORGAN STANLEY... (3 Replies)
Discussion started by: ragavhere
3 Replies
Login or Register to Ask a Question