Retrieve lines that match any occurence in a list of patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrieve lines that match any occurence in a list of patterns
# 8  
Old 08-29-2012
I have attached an printscreen of the output:
Image

rs-nr.txt is file 2 with the rs numbers only. Geno.csv is the total file.


Much appreciated!
# 9  
Old 08-29-2012
Please post the output of
Code:
head -2 Geno.csv|od -bc

# 10  
Old 08-29-2012
Here it is:
Image
# 11  
Old 08-29-2012
OK. It seems that file2 has some white-space before and/or after the data. Try this:
Code:
awk 'FNR==NR{a[toupper($1)]=1;next}(FNR!=1 && ($3 in a))||FNR==1' file2 file1

This User Gave Thanks to elixir_sinari For This Post:
# 12  
Old 08-29-2012
Unfortunately it still results in the header of file 1 only.
Might the fact the file 1 is tab delimited play a role?


Much appreciated!
# 13  
Old 08-29-2012
try using gsub on $0 of file2
This User Gave Thanks to raj_saini20 For This Post:
# 14  
Old 08-29-2012
Tried a replace of tabs to spaces. Unfortunately to no avail.

Talked to the owner of the file. It was DOS formatted and I forgot to check Smilie Smilie.

I did a
Code:
tr -d "\r"

on the file and then ran your code again. Lo-and-behold: it finally works! Smilie

Thanks a lot for your help. The line endings were my won stupid mistake, but the awk command I could not have dreamt.

As a final question, for me to learn, could you please give me a quick run-through of the command? A quick explantion is usually clearer than a trip through the MAN pages.

Thanks again.
This User Gave Thanks to Selftaught For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

Match 2 different patterns and print the lines

Hi, i have been trying to extract multiple lines based on two different patterns as below:- file1 @jkm|kdo|aas012|192.2.3.1 blablbalablablkabblablabla sjfdsakfjladfjefhaghfagfkafagkjsghfalhfk fhajkhfadjkhfalhflaffajkgfajkghfajkhgfkf jahfjkhflkhalfdhfwearhahfl @jkm|sdf|wud08q|168.2.1.3... (8 Replies)
Discussion started by: redse171
8 Replies

3. UNIX for Advanced & Expert Users

Get the first occurence between two patterns

I have an output file which gives me the timely status of a server. Sample file: March 11 2014 21:10, 1, 2, 3, 4, 5, 6, 7, 8, 9, x, y, z... 21:05, 1, 2, 3, 4, 5, 6, 7, 8, 9, x, y, z... 21:00, 1, 2, 3, 4,... (3 Replies)
Discussion started by: rpm120
3 Replies

4. Shell Programming and Scripting

Print between patterns - first occurence, second occurence etc

I have a file # cat asasas AAAAAA 11 22 33 44 BBBBB NILNILNIL AAAAAA 22 33 44 55 66 77 88 BBBBB NILNILNIL (2 Replies)
Discussion started by: anil510
2 Replies

5. Shell Programming and Scripting

sed print between 2 patterns only last occurence

Hi, I have a file, which contains the following log data. I am trying to print fromt he file the following data: I have tried using sed, but I am getting from the first pattern Thanks for your help. (5 Replies)
Discussion started by: sol_nov
5 Replies

6. Shell Programming and Scripting

How to get line after occurence of sequence of patterns

In the past I needed a help with the problem how to search for pattern after the occurence of another pattern which is described in this thread: https://www.unix.com/shell-programmin...-pattern1.html Now I would need something quite similar, only the pattern which is to be searched must be... (3 Replies)
Discussion started by: sameucho
3 Replies

7. Shell Programming and Scripting

print lines which match multiple patterns

Hi, I have a text file as follows: 11:38:11.054 run1_rdseq avg_2-5 999988.0000 1024.0000 11:50:52.053 run3_rdrand 999988.0000 1135.0 128.0417 11:53:18.050 run4_wrrand avg_2-5 999988.0000 8180.5833 11:55:42.051 run4_wrrand avg_2-5 999988.0000 213.8333 11:55:06.053... (2 Replies)
Discussion started by: annazpereira
2 Replies

8. Shell Programming and Scripting

Removing file lines that each match to a different patterns

I have a very large file (10,000,000 lines), that contains a sample id and a property of that sample. I have another file that contains around 1,000,000 lines with sample ids that I want to remove from the original file (create a new file without these lines). I know how to do this in Perl, but it... (9 Replies)
Discussion started by: Jo_puzzled
9 Replies

9. UNIX for Dummies Questions & Answers

retrieve lines that match a pattern

Hi, I would like to know how can I get lines from a text file that match no more than 2 '>'. Example: Input file: a >cr1 4 a>b b>c a >cr2 5 a>b Output file: a >cr2 5 a>b Thanks in advance (2 Replies)
Discussion started by: fadista
2 Replies

10. Shell Programming and Scripting

sed/awk help to match list of patterns and remove from org file

Hi, From the pattern mentioned below remove lines based on pattern range. Conditions 1 Look For all lines starting with ALTER TABLE and Ending with ; and contains the word MOVE.I wanto to remove these lines from the file sample below. Note : The above pattern list could be found in... (1 Reply)
Discussion started by: rajan_san
1 Replies
Login or Register to Ask a Question