ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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:
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.
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.