Single Field to multiple fields searching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Single Field to multiple fields searching
# 1  
Old 09-17-2014
Single Field to multiple fields searching

I have a fileA with one column (1000 rows), and fileB with 26 columns(13000 rows).
I need to search each value of fileA with fileB and return all the 26 values from FileB to a new file- File C if matches. The search value (from FileA) may present in any of the 26 values in FileB. This value is not fixed in any of the columns in B file.

FILEA:

abc
def
ghi
FILEB:

drm|fdm|pln|ess|abc|zeh|....|yer (26 values)
fdm|drm|def|ess|yer|zeh|....|pln

Here, abc from fileA is 5th col. of FileB-so my result should be all the 26 values from FileB to a new file- File C.
Similarly, def from fileA is 3rd col. of FileB -so my result should be all the 26 values from FileB to a new file- File C.

This way, need to do for the entire record set.

If unmatched, ignore the record.
# 2  
Old 09-17-2014
How about:

Code:
grep -wf FILEA FILEB

# 3  
Old 09-17-2014
Thanks for the reply!

This code is not working in this scenario. I need to search and return the values to the new file. Tried with the below code also, not worked. Please help if awk command or any other works.

Code:
grep -Fwf FileA FileB

# 4  
Old 09-18-2014
I don't understand what is not working are you getting any sort of error message?

If it's just not creating FileC with the results then just redirect the output like this:

Code:
grep -wf FileA FileB > FileC

# 5  
Old 09-18-2014
There is no error message, the new file is getting created. But it's an empty file!

grep -wf <server path fileA> <server path fileB> > <server path for new file with 777 permission>
# 6  
Old 09-18-2014
Code:
awk 'NR == FNR {A[$0]; next}
 {for(x in A) {if($0 ~ "(^||)" x "(||$)") {print; next}}}' FILEA FILEB > FILEC

# 7  
Old 09-18-2014
I'm surprised this didn't work for you.

It looks like your grep supports -w as you didn't get any errors about unknown parameters. What OS are you doing this on?

Perhaps the files are in DOS format, in which case SriniShoo's solution will probably result in no output either. You could try dos2unix FileA and dos2unix FileB and running the grep again.
This User Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How can I stack multiple (>1000) fields into one continuous field?

Hi, I'm struggling with a problem at the minute. Basically, I have a file with >1000 columns / fields (with headers), each containing a variable number of values. I would like to stack each column such that all the data appears in a single column, e.g. the first value of column 2 is moved to... (5 Replies)
Discussion started by: TAlcock
5 Replies

2. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

3. Shell Programming and Scripting

Inserting a field without disturbing field separator on other fields

Hi All, I have the input as below: cat input 032016002 2.891 97.109 16.605 27.172 24.017 32.207 0.233 0.021 39.810 0.077 0.026 19.644 13.882 0.131 11.646 0.102 11.449 76.265 23.735 16.991 83.009 8.840 91.160 0.020 99.980 52.102 47.898 44.004 55.996 39.963 18.625 0.121 1.126 40.189... (15 Replies)
Discussion started by: am24
15 Replies

4. Shell Programming and Scripting

awk - CSV file - field with single or multiple spaces

Hi, In a csv file, I want to select records where first column has zero or multiple spaces. Eg: abc.csv ,123,a ,22,b ,11,c a,11,d So output should be: ,123,a ,22,b ,11,c Please advise (5 Replies)
Discussion started by: vegasluxor
5 Replies

5. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

6. Shell Programming and Scripting

UNIX append field with comparing fields from multiple column

I have a csv dump from sql server that needs to be converted so it can be feed to another program. I already sorted on field 1 but there are multiple columns with same field 1 where it needs to be compared against and if it is same then append field 5. i.e from ANG SJ,0,B,LC22,LC22(0) BAT... (2 Replies)
Discussion started by: nike27
2 Replies

7. Shell Programming and Scripting

How to print 1st field and last 2 fields together and the rest of the fields after it using awk?

Hi experts, I need to print the first field first then last two fields should come next and then i need to print rest of the fields. Input : a1,abc,jsd,fhf,fkk,b1,b2 a2,acb,dfg,ghj,b3,c4 a3,djf,wdjg,fkg,dff,ggk,d4,d5 Expected output: a1,b1,b2,abc,jsd,fhf,fkk... (6 Replies)
Discussion started by: 100bees
6 Replies

8. Shell Programming and Scripting

Multiple lines in a single column to be merged as a single line for a record

Hi, I have a requirement with, No~Dt~Notes 1~2011/08/1~"aaa bbb ccc ddd eee fff ggg hhh" Single column alone got splitted into multiple lines. I require the output as No~Dt~Notes 1~2011/08/1~"aaa<>bbb<>ccc<>ddd<>eee<>fff<>ggg<>hhh" mean to say those new lines to be... (1 Reply)
Discussion started by: Bhuvaneswari
1 Replies

9. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

10. UNIX for Dummies Questions & Answers

Searching for fields in a file

Hi, I have a semi colon delimited file of following layout: FName;Email;LName;Age eg. Simon;simon@email.com;Pat;30 Pat;pat@simon@email.com;Simon;25 Sachin;sachin@email.com;Kambli;44 I want to get all records with a particular FName as Simon and LName Pat :confused: How do I dowit? ... (4 Replies)
Discussion started by: c2b2
4 Replies
Login or Register to Ask a Question