Visit Our UNIX and Linux User Community


Look for substrings with special characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Look for substrings with special characters
# 1  
Old 05-10-2016
Look for substrings with special characters

Hello gurus,

I have a lookup table

Code:
cat  tmp1
[//rtwttwtr*fgg]\\\erw``~ 1
^774574574565665f[[[//]\] 2
()42543^[[D^[[D^[[D^[[D^[[D353535345****@3242- 3


and I`m trying to compare a bunch of strings such that, either the lookup table column 1, or the string to be looked up are substrings of each other (and return the second lookup column if yes).

Code:
cat  tmp2
[//rtwtt
[//rtwttwtr*fgg]\\\erw``~
[//rtwttwtr*fgg]\\\erw``~4353535^^^7
()42543^[[D^[[D^[[D^[[D^[[D353535345****@3242--
rwerq5555525525

My desired output is


Code:
[//rtwtt 1
[//rtwttwtr*fgg]\\\erw``~ 1 
[//rtwttwtr*fgg]\\\erw``~4353535^^^7 1
()42543^[[D^[[D^[[D^[[D^[[D353535345****@3242-- 3
rwerq5555525525

Here is what I tried

Code:
awk 'NR==FNR{a[$1]=$2;next} { for(as in a) { if(($1~as) || (as~$1)) print $1,a[as]; continue}}' tmp1 tmp2


Also

Code:
awk 'NR==FNR{a[$1]=$2;next} { for(as in a) { if(($1~/as/) || (as~/$1/)) print $1,a[as]; continue}}' tmp1 tmp2

How can I tell the code to ignore the special characters and just compare the strings.
note: Either of the strings must fully contain the other string to satisfy the lookup.
# 2  
Old 05-11-2016
What are the special chars? And why is rwerq5555525525 in your desired output?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 05-11-2016
Quote:
Originally Posted by RudiC
What are the special chars? And why is rwerq5555525525 in your desired output?
The special characters come from a pedigree code in plant breeding which has all sorts of characters like [, ], *,- ,@ , /, \,(,) space embedded in alphanumeric strings. Do you need a super-set of all special characters?


rwerq5555525525 is included in the output without a lookup value since it, or any substring of it is not present in the lookup table.

Previous Thread | Next Thread
Test Your Knowledge in Computers #404
Difficulty: Easy
Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove special characters?

Hi Gurus, I have file which contains some unicode charachator like "". I want to replace it with some charactors. I searched in internet and got command sed "s//-/g", but I don't know how to type in unix command line. Please help me for this one. Thanks in advance (7 Replies)
Discussion started by: ken6503
7 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

Grep with special Characters

Need Help For GREP I have a file say g1.txt and content of file is below REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoDrives /t REG_DWORD /d 4 /f , REG ADD "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v NoClose /t REG_DWORD /d 1 /f ,... (4 Replies)
Discussion started by: jalpasoni
4 Replies

4. Shell Programming and Scripting

Replace special characters

I have a line ending with special character and 0 The special character is the field separator for this line in VI mode the file will look like below, but while cat the special character wont display i know the hexa code for the special character ^_ is \x1f and ascii code is \0037, ... (0 Replies)
Discussion started by: ratheeshjulk
0 Replies

5. 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

6. 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

7. 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

8. Shell Programming and Scripting

validation against special characters

I have a criteria like bloew. user entered the uid like <START_UID>-<END_UID> it menas if he enter 00001-12345 START_UID=00001 and END_UID=12345 both are separated by `-`. I need to validate whether user entered uids like above, he should have to enter '-', otherwise error msg has to... (4 Replies)
Discussion started by: KiranKumarKarre
4 Replies

9. UNIX for Dummies Questions & Answers

how to see special characters in a file using vi

Hi, I have a file which has special characters. I can't see them when I "vi" the file. But I am sure there are some special un seen characters. How can I see them? Please help. Thx (6 Replies)
Discussion started by: jingi1234
6 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

Featured Tech Videos