Use Regex to identify / format a complex string


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Use Regex to identify / format a complex string
# 1  
Old 06-01-2012
Data Use Regex to identify / format a complex string

First of all, please have mercy on me. I am not a noob to programming, but I am about as noob as you can get with regex. That being said, I have a problem.

I've got a string that looks something like this:

Code:
Publication - Bob M. Jones, Tony X. Stark, and Fred D. Man, \"Really Awesome Article Title Here,\" Journal of Awesome People and Stuff, vol. 139, no. 2, October 15, 1990,1,1, pp. 381-391.

And I want to format it so that it looks like this:
Code:
<h4><ul><li>\"Really Awesome Article Title Here,\"<br/><small>- Bob M. Jones, Tony X. Stark, and Fred D. Man<br/>- Journal of Awesome People and Stuff, vol. 139, no. 2, October 15, 1990,1,1, pp. 381-391.</small></li></ul></h4>

I've been trying to figure out 'sed', but for the life of me I can't understand regular expressions.

All I was able to come up with was this:

Code:
sed 's_Publication -\(.*\), \(".*"\)\( *\.\)_<h4><ul><li>\2<br/><small>- \1<br/>-\3</small></li></ul></h4>_g' < $infile > $outfile

But that doesn't work at all, and it probably has as many syntax errors as possible.

I realize that it may seem that I'm lazy and just want somebody to do this for me, but I am here to learn!

Last edited by radoulov; 06-01-2012 at 06:06 PM..
# 2  
Old 06-04-2012
Ok, I managed to get it.

Found out that the text editor I started using a couple days ago (TextWrangler, on Mac OS X) has support for grep built in.

Searched for this:

Code:
Publication - ([ a-zA-Z.]+), (\\"[^\\"]+\\") ([^\"]+)

and replaced it with:

Code:
<h4><ul><li>\2<br/><small>- \1<br/></small>\3</li></ul></h4>

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with understanding this regex in a Perl script parsing a 'complex' string

Hi, I need some guidance with understanding this Perl script below. I am not the author of the script and the author has not leave any documentation. I supposed it is meant to be 'easy' if you're a Perl or regex guru. I am having problem understanding what regex to use :confused: The script does... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. UNIX for Beginners Questions & Answers

Regex to identify pattern

Hi In a file I have string in multiple lines. Like below: <?=test.getObjectName("L", "testTBL","D") ?> <?=test.getObjectName("L", "testTBL","testDB", "D") ?> I want to use regex to search for the pattern "<?=test.getObjectName...?>" If the parenthesis has 3 parameters then return 2nd... (5 Replies)
Discussion started by: dashing201
5 Replies

3. Shell Programming and Scripting

Regex to identify illegal characters in a perso-arabic database

I am working on Sindhi: a perso-Arabic script and since it shares the Unicode-block with over 400 other languages, quite often the database contains characters which are not wanted: illegal characters. I have identified the character set of Sindhi which is given below: For clarity's sake, each... (8 Replies)
Discussion started by: gimley
8 Replies

4. Shell Programming and Scripting

Regex to identify unique words in a dictionary database

Hello, I have a dictionary which I am building for the Open Source Community. The data structure is as under HEADWORD=PARTOFSPEECH=ENGLISH MEANING as shown in the example below अ=m=Prefix signifying negation. अँहँ=ind=Interjection expressing disapprobation. अं=int=An interjection... (2 Replies)
Discussion started by: gimley
2 Replies

5. Shell Programming and Scripting

Identify lines with wrong format in a file and fix

Gurus, I have a data file which has a certain number of columns say 101. It has one description column which contains foreign characters and due to this some times, those special characters are translated to new line character and resulting in failing the process. I am using the following awk... (4 Replies)
Discussion started by: tumsri
4 Replies

6. Shell Programming and Scripting

Regex to identify word in second position on a line

I am interested in finding a regex to find a word in second position on a line. The word in question is या I tried the following PERL EXPRESSION but it did not work: ] या or ^\W या But both gave Null results I am giving below a Sample file: देना या सौंपना=delegate तह जमना या... (8 Replies)
Discussion started by: gimley
8 Replies

7. Shell Programming and Scripting

Regex to identify a full-stop as a sentence delimiter

Hello, Splitting a sentence using the full-stop/question-mark/exclamation is a common device. Whereas the question-mark / exclamation do not pose too much of a problem; the full-stop as a sentence delimiter raises certain issues because of its varied use: just to name a few. Standard parsers... (9 Replies)
Discussion started by: gimley
9 Replies

8. Shell Programming and Scripting

Complex Regex Perl

Hi the below perl snippet will replace any three letter string in the beginning with a two letter string which is specified..but if i want to modfiy only certain characters for eg.. ABC - AB CAB - AB AAA - No Modifcations 1AB - AB AB8 - AB Whatever coming before or after of AB only have... (2 Replies)
Discussion started by: rajkrishna89
2 Replies

9. Shell Programming and Scripting

How to identify whether the script is in Unix format or not ?

Hi All, I have the below scenario in my environment Developers used to copy file from windows to Linux box. Some time on the copied file developers miss to run the dos2unix utility. Because of this script gets failed during the execution. Most of the failures are due to the dos2unix format... (7 Replies)
Discussion started by: kalpeer
7 Replies

10. UNIX for Dummies Questions & Answers

Gathering data from complex/large dataspreads .txt format

Hi, I'm working on gathering information stored in .txt files. The format of the data within the .txt files is shown in the picture uploaded with this post. Sections like the one pictured are repeated (with different data, same format) many times within each .txt file but each section is of data... (4 Replies)
Discussion started by: p43hd
4 Replies
Login or Register to Ask a Question