Convert a list of word/terms into their Regexp representation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert a list of word/terms into their Regexp representation
# 1  
Old 11-30-2012
Convert a list of word/terms into their Regexp representation

Ok this might sound pretty weird but here is the request. Running on a linux system in bash or Perl (i really don't know perl but the end user has a few pearl script already)

Start File looks something like this (4000 entries)
TEST PLAN
T//TF
T-TF
TEST (T)
Hacker
...

I am thinking about loading each line then stepping through character by character into a regexp expression that covers Upper and lower cases. So the first line output should be:

[tT][eE][sS][tT][[:space:]][pP][lL][aA][nN]


ANY help would be appreciated, this is not for my section but a buddy in another section.
# 2  
Old 11-30-2012
What's the purpose of the conversion?
# 3  
Old 11-30-2012
To upload into a blocking file, blacklist.
# 4  
Old 12-01-2012
Wrench

Something to start with..
Code:
sed -e 's/[^ ]/[&\L&]/g' -e 's/\(.\)\1/\1\U\1/g'  filename

Or..
Code:
sed -e 's/[a-zA-Z]/[&\L&]/g' -e 's/\(.\)\1/\1\U\1/g' -e 's/ /[[:space]]/g' -e 's/[-\/)(]/[&]/g' infile


Last edited by michaelrozar17; 12-02-2012 at 03:31 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grep -B used with -f? (Searching a file using a list of terms, output is lines before each match)

(1 Reply)
Discussion started by: Twinklefingers
1 Replies

2. Shell Programming and Scripting

Convert a matrix to sparse representation

Hi All, I have a matrix stored in a file matrix.mtx and looks like this: 1 0.5 0.33 0.25 0 0.33 0.25 0.2 0 0 0 0.16 0 0 0 0.14 I want to convert this matrix to its sparse representation like the one give below (sparse_matrix.mtx). This means that above matrix has been converted to its... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

3. UNIX for Dummies Questions & Answers

regexp: match string that contains list of chars

Hi, I'm curious about how to do a very simple thing with regular expressions that I'm unable to figure out. If I want to find out if a string contains 'a' AND 'b' AND 'c' it can be very easily done with grep: echo $STRING|grep a|grep b|grep c but, how would you do that in a single... (9 Replies)
Discussion started by: jimcanoa
9 Replies

4. Programming

c++ function to convert a linear list to circular list

hi all, i need a c++ function which converts a linear list to circular. presently i am working with two files. i.e., one linear list file. and one circular list file to do some operations. i thought it will be helpful if there is a function that converts a linear list to circular n undo the... (1 Reply)
Discussion started by: vidyaj
1 Replies

5. Shell Programming and Scripting

Script to search a large file with a list of terms in another file

Hi- I am trying to search a large file with a number of different search terms that are listed one per line in 3 different files. Most importantly I need to be able to do a case insensitive search. I have tried just using egrep -f but it doesn't seam to be able to handle the -i option when... (3 Replies)
Discussion started by: dougzilla
3 Replies

6. Shell Programming and Scripting

Convert first character of each word to upper case

Hi, Is there any function(Bash) out there that can convert the first character of each word to upper case?... (3 Replies)
Discussion started by: harchew
3 Replies

7. Shell Programming and Scripting

Determining Word Frequency of Specific Terms

Hello, I require a perl script that will read a .txt file that contains words like 224.199.207.IN-ADDR.ARPA. IN NS NS1.internet.com. 4.200.162.207.in-addr.arpa. IN PTR beeriftw.internet.com. arroyoeinternet.com. IN A 200.199.227.49 I want to focus on words: IN... (23 Replies)
Discussion started by: richsark
23 Replies

8. Windows & DOS: Issues & Discussions

convert pdf's to word

Does anyone know any good tools to convert a pdf to word, I can usually cut & paste without a hitch but I have a pdf that doesn't like that and surrounds text with lines as though a table or prints tables in miniscule text. It's only one pdf file so I'm reluctant to buy a product. (3 Replies)
Discussion started by: gefa
3 Replies

9. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

10. Shell Programming and Scripting

Convert character in word to CAPS??

Hi Gurus!! Is it possible to change a letter in a word to CAPS?? When correcting a paragraph i need to covert the word if it appears at the start of a line to caps....... if i had a phrase like my name is james and would like to sign up. how do i convert "my" to "My" or the... (3 Replies)
Discussion started by: vadharah
3 Replies
Login or Register to Ask a Question