Question for SED preg_replace


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question for SED preg_replace
# 1  
Old 07-20-2012
Question for SED preg_replace

I want to make it in SED

PHP
PHP Code:
preg_replace('@<script[^>]*?>.*?</script>@siu','',$text); 

this is in AWK
Code:
awk '/<script /{p=1} /<\/script>/{p=0; next}!p'

can you help me to make it on SED working?

I have this
Code:
sed 's/<script[^>]*>[^>]*<\/script>//g'

but it not work with this string

Code:
<script type="text/javascript"> <s>Df<DF>FD>FD<DFd>FDF<>fgdfg dfgdfg fdg df g g</script>

only with this

Code:
<script type="text/javascript">fgdfg dfgdfg fdg df g g</script>

Thank you!

Last edited by sanantonio7777; 07-20-2012 at 01:04 PM..
# 2  
Old 07-20-2012
Hi sanantonio7777,

Welcome to the forum.

Could you please clarify what you have and what you want?
# 3  
Old 07-20-2012
Hi Smilie Thank you!

ok
I want to strip tags from html and to remove the letters between the tags with SED like this function in PHP
PHP Code:
preg_replace('@<script[^>]*?>.*?</script>@siu','',$text); 
and like this in awk
Code:
awk '/<script /{p=1} /<\/script>/{p=0; next}!p'

I want it the same in sed
# 4  
Old 07-20-2012
Hi,

maybe you should give a try to :

Code:
sed -r 's/<script[^>]*?>.*?<\/script>//g'

# 5  
Old 07-20-2012
Quote:
Originally Posted by Chirel
Hi,

maybe you should give a try to :

Code:
sed -r 's/<script[^>]*?>.*?<\/script>//g'

thank you but its not working in my source

Code:
echo $string | sed -r 's/<script[^>]*?>.*?<\/script>//g'

Quote:
sed: illegal option -- r
can you tell me why ?
# 6  
Old 07-20-2012
That's because i'm using GNU sed version 4.2.1

-r = --regexp-extended use extended regular expressions in the script.

What are you using ?
# 7  
Old 07-20-2012
Im with OS X LEOPARD 10.5 Smilie
can i fix this problem with sed ?

Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question on sed

How does sed substitutes a string of characters in a file and replace it with a string passed as an argument to a variable in a script and saves the file with the changes. Say for example read name sed 's/string1/$name/g filename BTW I am using /bin/sh (4 Replies)
Discussion started by: Tirmazi
4 Replies

2. Shell Programming and Scripting

Sed Question 1. (Don't quite know how to use sed! Thanks)

Write a sed script to extract the year, rank, and stock for the most recent 10 years available in the file top10_mktval.csv, and output in the following format: ------------------------------ YEAR |RANK| STOCK ------------------------------ 2007 | 1 | Exxon... (1 Reply)
Discussion started by: beibeiatNY
1 Replies

3. Shell Programming and Scripting

Another sed question

Hello, I am very new to shell scripting and have a directory path such as: /usr/dev/blah/Arch/release/812-1235-P05/files/list and I want to output: 812-1235-P05 I think using sed with a regex like --? would be the way to go, but I am having much trouble getting it to work. Any suggestions?... (4 Replies)
Discussion started by: phreezr
4 Replies

4. Shell Programming and Scripting

sed 's/\([^ ]* \)*/\1/g' question

It seems that I really need some serious regexp study, in the following example, >cat /tmp/test abc 7878 7878 7878 7878 123 123 123 345 234 345 345 345 345 >sed 's/\(* \)*/\1/g' /tmp/test 345 345 Why sed deletes all the columns except the last two ones? From what I understood, sed... (1 Reply)
Discussion started by: fedora
1 Replies

5. Shell Programming and Scripting

sed question

Hi I am trying to replace an extension in a file name using sed as follows: echo $filename | sed 's/.txt/.doc/' My objective is to replace any extension with let's say a .doc extension. Right now, my input may have two extensions; .txt and .csv. I have to replace both with a .doc... (17 Replies)
Discussion started by: Vikas Sood
17 Replies

6. Shell Programming and Scripting

sed question

all, I am trying to write a script that will dynamically change passwords within a group of files. Each file will have a record such as PASSWORD="xxxxxxxxx". I plan on creating a file with a list of passwords, (say 500,000) and then writing a 'for' loop that will cycle thru each, and replace... (5 Replies)
Discussion started by: hedrict
5 Replies

7. Shell Programming and Scripting

A sed question

I'm trying to use 'sed' to substitute some a string, but I can't get it to work. Can anyone help me, please? sed 's/d \qmaster\spool1\qmuser/temp_/' account1 > account There is a space between d and \qmaster (2 Replies)
Discussion started by: dbrundrett
2 Replies
Login or Register to Ask a Question