How to delete corrupted characters and then do fuzzy searches?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delete corrupted characters and then do fuzzy searches?
# 1  
Old 09-25-2010
How to delete corrupted characters and then do fuzzy searches?

Hi All

I have a whole block of pages that have come in from various sources, unfortunately the pages in many instances have blocks of corrupted text. What I'm trying to do is write a sed line that will just delete non alphanumeric characters if they're in a block of say three or four characters, i.e.

constipated would stay the same

con5tipated would stay the same

con%^|pated would stay the same

&*^%%pated would stay the same

^& would stay the same

&^*^ would get deleted

I was thinking along the lines of....

Code:
sed -r 's/^.*[[:punct:]]//g'

However this seems to delete anything with a punctuation character in the block even if they are valid alphanumerics.

I'm familiar with using /b for word blocks but unless I can get the core sed to work I'm stuck.

Could anyone possibly offer some pointers with an explanation of why my example doesn't work and there's does, that way it helps me learn.

Thanks in advance.
# 2  
Old 09-25-2010
I am not sure if I understand what you would like to achieve, but how about this for starters:
Code:
sed 's/[[:punct:]]\{4,\}//g' infile


Last edited by Scrutinizer; 09-25-2010 at 02:30 PM..
# 3  
Old 09-25-2010
Maybe I am missing something but why should
Code:
&*^%%pated

not be changed but
Code:
&^*^

would be deleted?
# 4  
Old 09-26-2010
Hi

Because there's fuzzy searching on keywords against the page to happen....

So you may be able to get a 'hit' on %&^%pated which will allow you to see manually if it's a match whereas ^*&^ (or any block of consecutive) non alpha characters are always a dud.

It's the results of the fuzzy search I'm really interested in so I don't want to delete too much data that may 'hit' but I do want to delete as much 'garbage' as possible to speed up search times.

Hope that makes it clearer?

Scrutinizer

Thanks for the code but it's not working the way I expected...for example

Code:
echo "&^^%% a" | sed  -r 's/[[:punct:]]\{4,\}//g'

outputs &^^%% a

whereas I expected it to output

a

Have I missed something?

I'm using Fedora 13
# 5  
Old 09-26-2010
Quote:
Originally Posted by Bashingaway
Have I missed something?
Hi, yes you should lose -r
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 10-01-2010
Thanks that got it working.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete special characters

My sed is not working on deleting the entire special characters and leaving what is necessary.grep connections_per a|sed -e 's/\<\!\-\-//g' INPUT: <!-- <connections_per_instance>1</connections_per_instance> --> <method>HALF</method> <!--... (10 Replies)
Discussion started by: kenshinhimura
10 Replies

2. Shell Programming and Scripting

Delete last characters in each column

I need to delete the last 11 characters from each number and they are all in the same line (each is in a different column): -6.89080901827020800000 3.49348891708562325136 1.47988367839905286876 -2.29707635413510400000 -3.49342364708562325136 -4.43758473239905286876 -2.29707635413510400000... (14 Replies)
Discussion started by: rogeriog.em
14 Replies

3. Shell Programming and Scripting

Delete and retain some characters

Ive been trying to google and tried sed and awk. BUt still getting no exact formula. I would like to know how to parse this at: From: Compute Machin Appliance 3.2.9.10000 123456 To: Compute Machin Appliance 3.2.9.123456 (5 Replies)
Discussion started by: kenshinhimura
5 Replies

4. Shell Programming and Scripting

delete first 2 characters for each line, please help

hi, ./R1_970330_210505.sard ./R1_970403_223412.sard ./R1_970626_115235.sard ./R1_970626_214344.sard ./R1_970716_234214.sard ... ... ... for these strings, i wanna remove the ./ for each line how can i do that? i know it could possibly be done by sed, but i really have not idea how... (4 Replies)
Discussion started by: sunnydanniel
4 Replies

5. Shell Programming and Scripting

need to Delete first 10 characters of a file name

Hello Everyone, I need help in deleting first 10 characters from the filename in a directory eg: 1234567890samplefile1.txt 1234567890samplefile2.txt and so on.. need to get the output as samplefile1.txt Thanks in Advance!!!! (8 Replies)
Discussion started by: Olivia
8 Replies

6. Shell Programming and Scripting

Delete characters from each line

Hi, I have a file that has data in the following manner, tt_0.00001.dat 123.000 tt_0.00002.dat 124.000 tt_0.00002.dat 125.000 This is consistent for all the entries in the file. I want to delete the 'tt_' and '.dat' from each line. Could anyone please guide me how to do this using awk or... (2 Replies)
Discussion started by: lost.identity
2 Replies

7. Shell Programming and Scripting

How to delete characters using a file

Hi All, I have a configuration file (file.cfg) in which data will be like this ; , _ + a to z A to Z Now i have to read a textfile (file.txt) and i need to check whether there is any other character present in text file that is not existing in (file.cfg). If other characters are present... (4 Replies)
Discussion started by: krishna_gnv
4 Replies

8. Shell Programming and Scripting

Delete not readable characters

Hi All, I wanted to delete all the unwanted characters in the string. ie, to delete all the characters which are not alpha numeric values. var1="a./bc" var2='abc/\."123' like to get the output as print var1 abc print var2 abc123 Could you guys help me out pls. Your help is... (3 Replies)
Discussion started by: ajilesh
3 Replies

9. UNIX for Dummies Questions & Answers

how to delete M-^M characters from a file

I am receiving a file with 'M-^M' characters...how do I get rid of these characters. I tried tr -d '\015' and sed '/^M//g', but they didnot work. Appreciate if someone can help me with this (1 Reply)
Discussion started by: hyennah
1 Replies

10. AIX

Delete specific characters

Hi every1 Well i have a list of numbers e.g 12304 13450 01234 00123 14567 what i want is a command to check if the number is starting from 0 and then delete the 0 without doing anything else!!!! any help wud b appreciated!!!!!!!!:( (4 Replies)
Discussion started by: masquerer
4 Replies
Login or Register to Ask a Question