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. |
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... |
Quote:
sed 's/\(\/.*\/\)\(.*\)/tag \1 ref \2 HREF \1\2/' yourfile check http://perso.club-internet.fr/thedec...wk/ch03_02.htm (from my sig) |
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.
|
As they say in Perl-land, "there's more than one way to do it!":)
perl -ne 'chomp; print "<a href=\"$_\">$_</a>\n";' |
All times are GMT -5. The time now is 08:07 PM. |