Search avoiding special characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search avoiding special characters
# 1  
Old 01-30-2014
Search avoiding special characters

Hi all,

I have a list which I want to search in another file.
I can do that using
grep -f

but the search is failing due to special characters, how do I solve this?

One row in that list is

Code:
amino-acid permease inda1 [Pyrenophora tritici-repentis  Pt-1C-BFP]gb|EDU41782.1| amino-acid permease inda1 [Pyrenophora  tritici-repentis Pt-1C-BFP]

Input file to be searched
Code:
comp1538736c0_seEON956710       5821833 putative amino-acid permease inda1 protein [Togninia minima UCRPA7]     1e-114  418     0       2       736     97      342     89.8%   80.1%
comp1538234c2_seEON956710       582.455 putative amino-acid permease inda1 protein [Togninia minima UCRPA7]     3e-18   96.7    2       2       229     338     413     71.1%   65.8%
comp1538600c3_seXP_001939063    5733127 amino-acid permease inda1 [Pyrenophora tritici-repentis Pt-1C-BFP]gb|EDU41782.1| amino-acid permease inda1 [Pyrenophora tritici-repentis Pt-1C-BFP]     5e-36   155     2       233     598     448 573      69.8%   59.5%

# 2  
Old 01-30-2014
In bash:
Code:
#!/bin/bash

declare -A ARR
while read line
do
        ARR["$line"]="$line"
done < file1


while read line
do
        for k in "${ARR[@]}"
        do
                [[ "$line" =~ "$k" ]] && echo "$line"
        done
done < file2

Input
Code:
$ cat file1
amino-acid permease inda1 [Pyrenophora tritici-repentis  Pt-1C-BFP]gb|EDU41782.1| amino-acid permease inda1 [Pyrenophora  tritici-repentis Pt-1C-BFP]

$ cat file2
comp1538736c0_seEON956710       5821833 putative amino-acid permease inda1 protein [Togninia minima UCRPA7]     1e-114  418     0       2       736     97      342     89.8%   80.1%
comp1538234c2_seEON956710       582.455 putative amino-acid permease inda1 protein [Togninia minima UCRPA7]     3e-18   96.7    2       2       229     338     413     71.1%   65.8%
comp1538600c3_seXP_001939063    5733127 amino-acid permease inda1 [Pyrenophora tritici-repentis  Pt-1C-BFP]gb|EDU41782.1| amino-acid permease inda1 [Pyrenophora  tritici-repentis Pt-1C-BFP]     5e-36   155     2       233     598     448 573      69.8%   59.5%

Output
Code:
$ ./look.bash
comp1538600c3_seXP_001939063    5733127 amino-acid permease inda1 [Pyrenophora tritici-repentis  Pt-1C-BFP]gb|EDU41782.1| amino-acid permease inda1 [Pyrenophora  tritici-repentis Pt-1C-BFP]     5e-36   155     2       233     598     448 573      69.8%   59.5%

# 3  
Old 01-30-2014
-F -f tells grep to consider them fixed strings, instead of regular expressions.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search special characters in a file and replace with meaningful text messages like Hello

Search special characters in a file and replace with meaningful text messages like Hello (2 Replies)
Discussion started by: raka_rjit
2 Replies

2. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

3. Shell Programming and Scripting

special characters

Hey guys, I'm trying to replace "]Facebook" from the text but sed 's/]Facebook/Johan/g' is not working could you please help me with that? (6 Replies)
Discussion started by: Johanni
6 Replies

4. UNIX for Dummies Questions & Answers

How to see special characters?

Hi all, I was wondering how can i see the special characters like \t, \n or anything else in a file by using Nano or any other linux command like less, more etc (6 Replies)
Discussion started by: gvj
6 Replies

5. Shell Programming and Scripting

awk search pattern with special characters passed from CL

I'm very new to awk and sed and I've been struggling with this for a while. I'm trying to search a file for a string with special characters and this string is a command line argument to a simple script. ./myscript "searchpattern" file #!/bin/sh awk "/$1/" $2 > dupelistfilter.txt sed... (6 Replies)
Discussion started by: cue
6 Replies

6. Shell Programming and Scripting

Special characters

When I open a file in vi, I see the following characters: \302\240 Can someone explain what these characters mean. Is it ASCII format? I need to trim those characters from a file. I am doing the following: tr -d '\302\240' ---------- Post updated at 08:35 PM ---------- Previous... (1 Reply)
Discussion started by: sid1982
1 Replies

7. SCO

Avoiding duplicates with some special case

Hi Gurus, I had a question regarding avoiding duplicates.i have a file abc.txt abc.txt ------- READER_1_1_1> HIER_28056 XML Reader: Error occurred while parsing:; line number ; column number READER_1_3_1> Sun Mar 23 23:52:48 2008 READER_1_3_1> HIER_28056 XML Reader: Error occurred while... (0 Replies)
Discussion started by: pssandeep
0 Replies

8. Shell Programming and Scripting

Perl code to search for filenames that contain special characters

Hello, I have a requirement to search a directory, which contains any number of other directories for file names that contain special characters. directory structure DIR__ |__>DIR1 |__>DIR2__ |__>DIR2.1 |__>DIR2.2 |__>DIR3 .. ... (8 Replies)
Discussion started by: jerardfjay
8 Replies

9. UNIX for Dummies Questions & Answers

search special characters in a file

Hello I am new to shell scripting and can anyone tell me how to check if there are any special characters in a file. Can i use grep ? thanks susie (2 Replies)
Discussion started by: cramya80
2 Replies

10. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question