Sponsored Content
Top Forums Shell Programming and Scripting Look for substrings with special characters Post 302972773 by sheetalk on Tuesday 10th of May 2016 05:51:33 PM
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.
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 08:48 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy