need a little kick with sed, got it almost but on glitch


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need a little kick with sed, got it almost but on glitch
# 1  
Old 06-16-2008
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  
Old 06-16-2008
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  
Old 06-16-2008
Code:
sed "s/http:\/\/[^\/]*/&.APPENDTHIS/g"

Should work and be cleaner...
# 4  
Old 06-16-2008
thanks Tytalus, nice one
thats what i call a fast answer SmilieSmilieSmilieSmilie

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conditional delete -- New glitch

Hi Please dont consider this as duplicated post.. I am using below pattern to find delete files to bringdown disc size.. however how i can make sure ist going to correct folder and searching for files... while print "echo rm " LastFile correctly print files names for deletion, but when i... (7 Replies)
Discussion started by: onenessboy
7 Replies

2. Shell Programming and Scripting

Crontab does not kick at the given time

I have crontab set to be triggered daily @ 8 am and 8:20 am server time. 00 08 * * * /web/scripts/check.sh 20 08 * * * /web/scripts/check.shuname -a Linux mymac 3.10.0-327.36.3.el7.x86_64 #1 SMP Thu Oct 20 04:56:07 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux ls -ltr /web/scripts/check.sh... (9 Replies)
Discussion started by: mohtashims
9 Replies

3. UNIX for Dummies Questions & Answers

Need cronjob to kick at a specific time

Hi, I need to schedule a cronjob to kick start @ 8:30 PM server time and run every 5 mins there upon till I force stop it. Can you please let me know how can it be achieved ? (5 Replies)
Discussion started by: mohtashims
5 Replies

4. Red Hat

Need Kick Start Post and Preinstallation Scripts

Hi All Rhel Admin Need a Small Help please Give me a Preinstallation Script and postinstallation script for Kickstart Preinstallation script Just Need to Partition 1 TB HDD using LVM Except Boot /boot = 500 swap = 16 GB / = 850 Gb 8e And need to format it in ext4 ... (1 Reply)
Discussion started by: babinlonston
1 Replies

5. Red Hat

how to re-create kick start bootable ISO

Hi All, I want to create kick start bootable ISO file. I have Centos 5.4 ISO and customized ks.cfg file. Now I need to recreate ISO with ks.cfg and content of existing ISO. During installation, it automatically should pick the kick start file and need to proceed with the installation. ... (0 Replies)
Discussion started by: kalpeer
0 Replies

6. Shell Programming and Scripting

use statements and system glitch

hi, i have a perl script that runs as a cron job... Once in a while, the perl script fails with: Can't locate <module>.pm in @INC (@INC contains: .............) because one of the perl modules specified in the "use" statements is unavailable due to an NFS glitch. Is there some... (1 Reply)
Discussion started by: Andrewkl
1 Replies

7. Shell Programming and Scripting

Help with kick user in network script.

Hello ! I am new at this and could use som help with at script i want to do. I have a ubuntu server and want a script that check how long time a user has been login. If a user in the network has been login more the 10min i want the user get the messege " You have been login to long". An after... (1 Reply)
Discussion started by: smurfen
1 Replies

8. Ubuntu

Ubuntu costumized like OSX glitch

I have a laptop running Ubuntu Gusty. I have recently used applications such as AWN, Emerald, etc... to create a Mac OS X Leopard like environment. It works almost perfectly except for one little glitch. When I open most of my apps/windows, they all open with the top bar(with includes close,... (5 Replies)
Discussion started by: Texasone
5 Replies

9. UNIX for Advanced & Expert Users

Kick off Application on PC from Sun

I need to kick off an application on windows from my sun workstation. The workstation needs to know when windows application completes the job. What are the possible ways of doing it. Any ideas on how to go about doing it will be very helpful. Thxs in advance. (9 Replies)
Discussion started by: vbshuru
9 Replies
Login or Register to Ask a Question