LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-21-2002, 03:53 PM   #1
d3funct
Member
 
Registered: Jun 2001
Location: Centralia, WA
Posts: 274

Rep: Reputation: 31
Need a regex, I suck at regex's


Hi, I'm working on a 6000 line file full of document links that I need to html tag for a web page. I got the file by doing an 'ls -ltRa' of my server document directory. The output I got goes something like this:

/documents/serverA/pdfs/somefile.pdf
/documents/serverA/images/someimage.jpg
/documents/serverA/docs/somedoc.doc


What I want to do is use a regex to make the path an html tag and then use the document name as the reference to the path. But, I want to keep the filename in the path AND use it in the HREF. Any suggestions would be appreciated.
 
Old 02-21-2002, 04:44 PM   #2
Malicious
Member
 
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
Lesson number 1.

sed 's/\(\/.*\/\)\(.*\)/tag \1 ref \2 HREF \1\2' yourfile

Will output:

tag /documents/serverA/pdfs/ ref somefile.pdf HREF /documents/serverA/pdfs/somefile.pdf

Can you take it from there? The parens delimit a matched string and you can reference that on the substitution side with \n where n in the matched set, 1 being the first.

There will be a quiz...
 
Old 02-21-2002, 05:21 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally posted by Malicious
Lesson number 1.

sed 's/\(\/.*\/\)\(.*\)/tag \1 ref \2 HREF \1\2' yourfile

Will output:

tag /documents/serverA/pdfs/ ref somefile.pdf HREF /documents/serverA/pdfs/somefile.pdf

Can you take it from there? The parens delimit a matched string and you can reference that on the substitution side with \n where n in the matched set, 1 being the first.

There will be a quiz...
correction-
sed 's/\(\/.*\/\)\(.*\)/tag \1 ref \2 HREF \1\2/' yourfile

check http://perso.club-internet.fr/thedec...wk/ch03_02.htm (from my sig)

Last edited by acid_kewpie; 02-21-2002 at 05:28 PM.
 
Old 02-21-2002, 06:10 PM   #4
Malicious
Member
 
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
Damn, hate it when that happens! Missed a slash (slant, stroke, whatever). I had to turn in my slash key at the airport gate; they thought I could hurt somebody with it. Sure 'nuff.
 
Old 02-25-2002, 08:28 PM   #5
mtsinc
LQ Newbie
 
Registered: Jan 2002
Location: Jacksonville, FL
Distribution: RedHat
Posts: 26

Rep: Reputation: 16
As they say in Perl-land, "there's more than one way to do it!"

perl -ne 'chomp; print "<a href=\"$_\">$_</a>\n";'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LOL I suck {DoG}Corpse Linux - Newbie 30 09-13-2005 05:09 PM
Regex Help cmfarley19 Programming 5 03-31-2005 10:13 PM
Does Linux Suck!!!! Agent0013 Slackware 19 03-02-2004 02:58 PM
GNU C++ Regex lumux Programming 5 09-29-2003 10:51 PM
Dependencies suck florinel Linux - General 1 08-23-2003 09:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration