Match tab-delimited files based on key


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Match tab-delimited files based on key
# 8  
Old 06-01-2018
PLEASE start becoming exact and consistent when posting your problems here, also across posts, making samples match what you say in the text.
People (not only) in here tend to refer to the samples if the text is not too clear...
Also, stick to lower or upper case syntax as, in *nix, these are not equivalent: "FILE2" != "file2"!
For example, your for i in *.txt won't match ANY of your "FILE1..." names in post#7.



Quote:
Originally Posted by andmal
. . .

Then add the .pruned extension to the stdout file?

We don't print to stdout, but redirect it to a filename composed of the original name (which awk provides in the FILENAME variable) and the ".pruned" extension (pls be aware that *nix doesn't have the concept of file name "extensions").

Quote:
I also don't understand this part


Code:
FILE2 FILE1[^2].txt

Does the ^ mean that the files are combined?
That's shell's file name globbing: match any char EXCEPT "2" in the directory's entries. c.f. man bash




Quote:
Is it possible to use wildcard definition e.g. *.tab to process many different versions of FILE1?
Try the above script like
Code:
awk ' ... ' FILE2.txt FILE1*.tab

or even drop the FILE1 part.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 06-01-2018
you might/will run out of the opened file descriptors.
Here's a slight variation on the theme:
Code:
awk '
FNR==NR         {f21[$1]=$3
                 f22[$2]=$3
                 next
                }
FNR==1        { if(fout) close(fout); fout=(FILENAME ".pruned") }
$1 in f21       { print $0, f21[$1] > fout; next }
$1 in f22       { print $0, f22[$1] > fout }
' FILE2.txt FILE1*.tab

This User Gave Thanks to vgersh99 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

Replace a column in tab delimited file with column in other tab delimited file,based on match

Hello Everyone.. I want to replace the retail col from FileI with cstp1 col from FileP if the strpno matches in both files FileP.txt ... (2 Replies)
Discussion started by: YogeshG
2 Replies

2. UNIX for Beginners Questions & Answers

UNIX - 2 tab delimited files, conditional column extraction

Please know that I am very new to unix and trying to learn 'on the job'. I'm only manipulating large tab-delimited files (millions of rows), but I'm stuck and don't know how to proceed with the following. Hoping for some friendly advice :) I have 2 tab-delimited files - with differing column &... (10 Replies)
Discussion started by: GTed
10 Replies

3. Shell Programming and Scripting

Merge multiple tab delimited files with index checking

Hello, I have 40 data files where the first three columns are the same (in theory) and the 4th column is different. Here is an example of three files, file 2: A_f0_r179_pred.txt Id Group Name E0 1 V N(,)'1 0.2904 2 V N(,)'2 0.3180 3 V N(,)'3 0.3277 4 V N(,)'4 0.3675 5 V N(,)'5 0.3456 ... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

4. UNIX for Dummies Questions & Answers

Need to convert a pipe delimited text file to tab delimited

Hi, I have a rquirement in unix as below . I have a text file with me seperated by | symbol and i need to generate a excel file through unix commands/script so that each value will go to each column. ex: Input Text file: 1|A|apple 2|B|bottle excel file to be generated as output as... (9 Replies)
Discussion started by: raja kakitapall
9 Replies

5. UNIX for Dummies Questions & Answers

How to sort the 6th field of tab delimited files?

Here's a sample of the data: NAME BIRTHDAY SEX LOCATION AGE ID Jim 05/11/1986 M Japan 27 86 Rei 08/25/1990 F Korea 24 33 Jane 02/24/1985 F India 29 78 I've been trying to sort files using the... (8 Replies)
Discussion started by: maihani
8 Replies

6. Shell Programming and Scripting

Insert a header record (tab delimited) in multiple files

Hi Forum. I'm struggling to find a solution for the following issue. I have multiple files a1.txt, a2.txt, a3.txt, etc. and I would like to insert a tab-delimited header record at the beginning of each of the files. This is my code so far but it's not working as expected. for i in... (2 Replies)
Discussion started by: pchang
2 Replies

7. UNIX for Dummies Questions & Answers

How to use the join command to obtain tab delimited text files as an output?

How do you use the join command and obtain tab delimited text files as an output? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

8. UNIX for Dummies Questions & Answers

tab delimited file that is not tab delimited.

Hi Forum I have a tab delimited file that opens well in Openoffice calc (excel). But when I perform any operation in command line, it reads the file incorrectly. When I 'save As' the same file in office as tab delimited then it works fine. The file that I think is tab delimited is actually... (8 Replies)
Discussion started by: imlearning
8 Replies

9. Shell Programming and Scripting

Merging files into a single tab delimited file with a space separating

I have a folder that contains say 50 files in a sequential order: cdf_1.txt cdf_2.txt cdf_3.txt cdf_3.txt . . . cdf_50.txt. I need to merge these files in the same order into a single tab delimited file. I used the following shell script: for x in {1..50}; do cat cdf_${x}.txt >>... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

10. Shell Programming and Scripting

Working with Tab-Delimited files

I have a tab-Delimited file: Eg: 'test' file contains: a<tab>b<tab>c<tab>.... Based on certain condition, I wanna increase the number of lines of this file.How do I do that Eg: If some value in the database is 1 then one line in 'test' file is fine.. If some value in the database is 2... (1 Reply)
Discussion started by: shiroh_1982
1 Replies
Login or Register to Ask a Question