[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: help needed for converting strings in a file



On Thu, Nov 10, 2005 at 09:22:53PM +0530, Sourabh Bora wrote:
> In a web page the hyper links are written as
> 
> href="http://www.micronux.com/catalog/";
> 
>       i want this particular string to convert to
> 
> 
> href="./micronux.com_catalog"
> 
>       The logic is --1)delete http://www.
>                       2) replace '/' '?' etc with '_'
> 

With sed and tr:

$ echo http://www.micronux.com/catalog/ | sed "s|http://www.|./|g" | tr "?/" _

or completely with sed:

$ echo http://www.micronux.com/catalog/ | sed "s|http://www.|./|g;s|[?/]|_|g"

Result:

._micronux.com_catalog_

You should be able to get rid of that underscore at the end if you
want.  If it doesn't work, come back to the list.

Thanks go to Michael Marsh in this thread for showing that you can use
'|' (or any character actually) instead of '/' as the delimiter in
regular expressions.  I wish I had known that earlier. :)

HTH,

-- 
Maurits van Rees | http://maurits.vanrees.org/ [Dutch/Nederlands] 
Public GnuPG key:  http://maurits.vanrees.org/var/gpgkey.asc
"Make no little plans; they have no magic to stir men's blood and
probably in themselves will not be realized. Make big plans."
---Daniel Hudson Burnham.

Attachment: signature.asc
Description: Digital signature


Reply to: