Visit Our UNIX and Linux User Community


how to grep special character regular expression?


 
Thread Tools Search this Thread
Operating Systems Linux how to grep special character regular expression?
# 1  
Old 09-23-2009
how to grep special character regular expression?

Hi Smilie

I have 2 files

file1:

Code:
SNP_A-2208459   
SNP_A-4215188   
SNP_A-2012248   
SNP_A-1882998


file2:

Code:
CHR  SNP  UNADJ       BONF         HOLM     *   *    *  etc.
  19   SNP_A-2236481  1.742e-26  5.442e-21    
  13   SNP_A-4204405  8.643e-07  1.505e-06   
   3    SNP_A-1860908  4.483e-06  7.279e-06
   7    SNP_A-1990194  7.434e-06  1.181e-05
   *
   *
   *
   etc. (thousands of rows)

Note: file2 also contains the entries listed in file1

Question: I'm using grep -w -f file1 file2 > file3 to match in file2 only the entries listed in file1, BUT this does not work Smilie ; the output file3 is giving me everything listed in file2 Smilie.

Can anyone help? pleaaaaaaaaaaaaase

Thank you!

Last edited by vgersh99; 09-23-2009 at 06:49 PM.. Reason: code tags, PLEASE!
# 2  
Old 09-23-2009
What does -F do if used instead of -f?
# 3  
Old 09-23-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 4  
Old 09-23-2009
-F does not work only either.
# 5  
Old 09-24-2009
1. -w means word. And -(hyphen) is not a word character.

So file3 will not have any content, ( by the sample input you gave ). Confirm whether you are right in saying that.

2. Solution.
Code:
grep -f file1 file2

Let us know whether this helped.
# 6  
Old 09-25-2009
thegeek;

Thank you for trying to help me, but grep -f file1 file2 > file3
DOES NOT WORK.


---------- Post updated 09-25-09 at 03:56 PM ---------- Previous update was 09-24-09 at 09:47 PM ----------

I also deleted the hyphens, underscores and letters from the in both files but the grep -f file1 file2 > file3 does not work
SNP_A-2208459

---------- Post updated at 03:58 PM ---------- Previous update was at 03:56 PM ----------

Ok, I give up with this forum, I guess nobody wants to help.
# 7  
Old 09-25-2009
did you try the man pages?

i think diff may be another way around it check man diff also

Previous Thread | Next Thread
Test Your Knowledge in Computers #798
Difficulty: Medium
To convert from a base-10 integer to its base-2 (binary) equivalent, the number is divided by two and the remainder is the least-significant bit.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep regular expression

I want to track only below: I am using below, but it doesn't work: (6 Replies)
Discussion started by: proactiveaditya
6 Replies

2. Shell Programming and Scripting

Grep + Regular expression or

Hi , I have few lines like A20120101.ANU.ZIP A20120401.ABC.ZIP A20120105.KJK.ZIP A20120809.JUG.ZIP A20120101.MAT.ZIP B20120301.ANU.XIP I want to filter by 1. Files starting with A and Ending With Z ( ^A.*.ZIP$) 2. And either ANU, or KJK or MAT in the file name. Hope my... (6 Replies)
Discussion started by: Anupam_Halder
6 Replies

3. Shell Programming and Scripting

perl regular expression to remove the special characters

I had a string in perl script as below. Tue Aug7 03:54:12 2012 Now I need to replace the special character with space. After removing the special chaacters Tue Aug 7 03:54:12 2012 Could anyone please help me here for writing the regular expression? Thanks in advance.. Regards, GS (1 Reply)
Discussion started by: giridhar276
1 Replies

4. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

5. Shell Programming and Scripting

Help with grep / regular expression

Hi, Input file: -13- -1er- -1xyz1- -1xz12- -2ab1- -2ab2-- -143- Code: grep '^*\-' input.txt Wrong output: -13- -1xyz1- -2ab1- -2ab2-- (4 Replies)
Discussion started by: dragon.1431
4 Replies

6. Shell Programming and Scripting

grep and regular expression

Hi, I am executing a svnlook command to check to see if the following line exists. I need a regular expression to represent the line. A /test/test1/qa/test2/index.html A /test/test1/qa/test3/test.jpg A /test/test1/qa/test3/test1.jpg A /test/test1/qa/test4/test.swf I just need to extract... (9 Replies)
Discussion started by: kminkeller
9 Replies

7. Shell Programming and Scripting

grep regular expression

please can someone tell me what the following regrex means grep "^aa*$" <file> I thought this would match any word beginning with aa and ending with $, but it doesnt. Thanks in advance Calypso (7 Replies)
Discussion started by: Calypso
7 Replies

8. Shell Programming and Scripting

grep with regular expression

Hi, guys. I have one question, hope somebody can give me a hand I have a file called passwd, the contents of it arebelow: *********************** ... goldsimj:x:5008:200: goldsij2:x:5009:200: whitej:x:5010:201: brownj:x:5011:202: goldsij3:x:5012:204: greyp:x:5013:203: ...... (6 Replies)
Discussion started by: daikeyang
6 Replies

9. UNIX for Advanced & Expert Users

regarding grep regular expression

When i do ls -ld RT_BP* i am getting the following list. drwxrwx--- 2 user group 256 Oct 17 10:09 RT_BP809 drwxrwx--- 2user group 256 Oct 17 10:09 RT_BP809.O drwxrwx--- 2 user group 256 Oct 17 10:09 RT_BP810 drwxrwx--- 2user group 256 Oct... (2 Replies)
Discussion started by: ukatru
2 Replies

10. Shell Programming and Scripting

grep : regular expression

guys, my requirment goes like this: I have a file, and wish to filter out records where 1. The first letter is o or O and 2. The next 4 following letter should not be ther I do not wish to use pipe and wish to do it in one shot. The best expression I came up with is: grep ^*... (10 Replies)
Discussion started by: RishiPahuja
10 Replies

Featured Tech Videos