1828586 Members
2626 Online
109982 Solutions
New Discussion

sed and c-shell script

 
SOLVED
Go to solution
Maureen Gunkel
Trusted Contributor

sed and c-shell script

I am trying to change a line in some files after I have received them via ftp. It's a pretty simple edit, but I can't seem to get it to work. Following is the line in the file I'm trying to change:

The file name "SHbe1820.jpg" changes with each file I get and on a daily basis.
Following is the line in my sed script:
s/img src="*.jpg/img src="{!=VW_UCntx.getDocsURL()!}/images/complogo.jpg/g
Can anyone tell me what I'm doing wrong?
Thanks!
No matter where you go, there you are.
6 REPLIES 6
RikTytgat
Honored Contributor

Re: sed and c-shell script

Maureen,

Could you put the line in question in a file and append it to a post in this thread.

It looks a kind of complicated (and maybe some characters got lost).

Bye,
Rik
Maureen Gunkel
Trusted Contributor

Re: sed and c-shell script

Here it is!
No matter where you go, there you are.
Madhu Sudhan_1
Respected Contributor

Re: sed and c-shell script

Assumption made:
every day you get which file to replace with what and its new path.

Based on the above,
sed 's/somefile.jpg//newlocation/subdirectory/otherfile.jpg/g' test.old > tests.html

To hint you . is treated as any character in the regular expression you are searching for, Incase if your reg-exp has / to be searched or replace you need to prefix with to negate the meaning what sed has.

Hope this helps.
......Madhu
Think Positive
Alan Riggs
Honored Contributor
Solution

Re: sed and c-shell script

Two things:
1) You need to wildcard more specifically in sed. '*' just menas any number of the preceding character. '.*' gets you what you want.
2) You cannot use / within a replacement string if you are using it as teh string delimiter. You can get around this by escaping the / with \ inside the replacement, but that gets ugly pretty quickly. I find it cleaner to simply use another character as my string delimiter in sch situations. In the example below, I have used %.


sed 's%img src=".*.jpg%img src="{!=VW_UCntx.getDocsURL()!}/images/complogo.jpg%g'
Madhu Sudhan_1
Respected Contributor

Re: sed and c-shell script

Maureen : Looked at the attachment, when you prefix with *, It literally looks for character "*" not for anything.

Thanks,
Madhu
Think Positive
Maureen Gunkel
Trusted Contributor

Re: sed and c-shell script

Alan:

Thank you, thank you, thank you. Works like a charm. My butt is now off the 'hot seat'!

Mo
No matter where you go, there you are.