The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ubuntu costumized like OSX glitch Texasone Ubuntu 5 06-16-2008 05:22 PM
Commentary: ISO should kick OOXML off the standards bus iBot UNIX and Linux RSS News 0 01-26-2008 10:30 AM
Kick off Application on PC from Sun vbshuru UNIX for Advanced & Expert Users 9 11-21-2003 12:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-16-2008
scarfake scarfake is offline
Registered User
  
 

Join Date: May 2008
Posts: 43
need a little kick with sed, got it almost but on glitch

hi friends.

yo i have a textfile with urlīs in it

sometimes middle in text, sometimes one url alone is a line

i append a string right behind the domain name

so that http://unix.com becomes http://unix.com.APPENDTHIS on all occasions.

i use this sed-line to achieve this:

Code:
sed -i "s/http:\/\/[a-zA-Z0-9\_\-\.]*/&.APPENDTHIS/g" FILE

now my problem is when the url contains a dash it messes up.

test input file:
Code:
http://alf.com/super.cgi
http://frederick.xoom.com/homepage/xy.htm
http://james_007.web1000.com/
http://unix-windows.com/bluescreen.txt


Code:
http://alf.com.APPENDTHIS/super.cgi
http://frederick.xoom.com.APPENDTHIS/homepage/xy.htm
http://james_007.web1000.com.APPENDTHIS/
http://unix.APPENDTHIS-windows.com/bluescreen.txt

the last url with the - dash in it messes up. it appends "APPENDTHIS" after the dash instead there where the domain-name ends.
what do i do wrong?
i tried to unescaped dash and double escaped also.

thanks for the needed kick.
  #2 (permalink)  
Old 06-16-2008
scarfake scarfake is offline
Registered User
  
 

Join Date: May 2008
Posts: 43
as so soften when i request help on here,
i find the solution myself
old:

Code:
sed -i "s/http:\/\/[a-zA-Z0-9\_\-\.]*/&.APPENDTHIS/g" FILE

new, working:

Code:
sed -i "s/http:\/\/[a-zA-Z0-9\_--\.]*/&.APPENDTHIS/g" FILE

instead of escaping the dash i have to double it.

dont know why, just tested some variations and this one works.

anyone any comment why?
  #3 (permalink)  
Old 06-16-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431

Code:
sed "s/http:\/\/[^\/]*/&.APPENDTHIS/g"

Should work and be cleaner...
  #4 (permalink)  
Old 06-16-2008
scarfake scarfake is offline
Registered User
  
 

Join Date: May 2008
Posts: 43
thanks Tytalus, nice one
thats what i call a fast answer

this only works when the domain is trailed by a slash unix.com/ but not with unix.com

but i found a workaround now.


Code:
sed -i "s/http:\/\/[-a-zA-Z0-9\_\.]*/&APPENDTHIS/g"

this one works smooth wherever the pattern occurs, wheter a linebreak follow or binary.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0