[opensuse] OT: Need program to replace text
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code 2.rename the file to .php Isn't there a program that will search all the files in a given directory for html and head and then replace that with something else? Then rename the files? I have seen the replace function in gedit but it does not accept the php code that needs to be inserted (i think the code is to long). Anyone no of a program/way that will accomplish this? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Am Sonntag, 11. November 2007 01:41:44 schrieb Chris Arnold:
file to .php
Isn't there a program that will search all the files in a given directory for html and head and then replace that with something else? Then rename the files? I have seen the replace function in gedit but it does not accept the php code that needs to be inserted (i
$ sed -i 's/red/blue/g' file to replace every entry called red with one that's called blue and write it in the file(-i). You can of course use such things as ./* for the hole directory.... man sed or man awk will provide you with further informations :) Greetings Michael
$ sed -i 's/red/blue/g' file to replace every entry called red with one that's called blue and write it in the file(-i). You can of course use such things as ./* for the hole directory.... man sed or man awk will provide you with further informations :) I have a long replacement text like this: <?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content"> and the text that needs to be replaced is: <HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title> So the command i run looks like this; sed -i 's/<HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>/<?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">/g' ./* and i get this error: sed: -e expression #1, char 99: unknown option to `s' -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Am Sonntag, 11. November 2007 03:27:54 schrieb Chris Arnold:
$ sed -i 's/red/blue/g' file
to replace every entry called red with one that's called blue and write it in the file(-i). You can of course use such things as ./* for the hole directory....
man sed or man awk will provide you with further informations :)
I have a long replacement text like this: <?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">
and the text that needs to be replaced is: <HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>
So the command i run looks like this; sed -i 's/<HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>/<?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">/g' ./*
and i get this error: sed: -e expression #1, char 99: unknown option to `s'
I guess you've to escape various symbols first ;) Greetings Michael
On Sat, 10 Nov 2007, Chris Arnold wrote:- <snip>
So the command i run looks like this; sed -i 's/<HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>/<?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">/g' ./*
and i get this error: sed: -e expression #1, char 99: unknown option to `s'
Try replacing the delimiters with some other character, e.g. '#' sed -i 's#<HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>#<?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">#g' ./* Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-P2 @ ~100Mnodes RC5-72 @ ~15Mkeys | SUSE 10.1 32bit | openSUSE 10.2 32bit | openSUSE 10.3 32bit SUSE 10.0 64bit | SUSE 10.1 64bit | openSUSE 10.2 64bit | RISC OS 3.11 | RISC OS 3.6 | TOS 4.02 | openSUSE 10.3 PPC -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Chris Arnold schreef:
$ sed -i 's/red/blue/g' file
to replace every entry called red with one that's called blue and write it in the file(-i). You can of course use such things as ./* for the hole directory....
man sed or man awk will provide you with further informations :)
I have a long replacement text like this: <?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">
and the text that needs to be replaced is: <HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>
So the command i run looks like this; sed -i 's/<HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>/<?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">/g' ./*
and i get this error: sed: -e expression #1, char 99: unknown option to `s'
There are a couple of reasons why this does not work. First and foremost: since your replacement text contains '/', you should use a text separator different from '/' like s#foo#bar#g If I remember correctly < and > are also special (have to look that up) and you should escape them: \< and \>. Finally, this would only work on a consecutive text without newlines and I think that is not what you have in mind. Look up the c command in sed, because I think that is what you need. This lets you replace a couple of lines with a couple of other lines. -- Jos van Kan registered Linux user #152704 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
There are a couple of reasons why this does not work. First and foremost: since your replacement text contains '/', you should use a text separator different from '/' like s#foo#bar#g If I remember correctly < and > are also special (have to look that up) and you should escape them: \< and \>. Finally, this would only work on a consecutive text without newlines and I think that is not what you have in mind. Look up the c command in sed, because I think that is what you need. This lets you replace a couple of lines with a couple of other lines. OK, i have looked up the c command nd run this command: sed -ic 's#<HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>#<?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">#g' ./* And this time, i do not get an error and i am left at the prompt. Then i check 1 of the files and nothing has been replaced. So, is my syntax for the c command in sed right (sed -ic)? I tried sed -c and got an invalid --c option. I wonder if some of the problem is that the <TITLE>Net Bible - Genesis </TITLE> line is different for every file. In other words, for the book of Genesis, for every chapter (every chapter is a new file), this line would read <TITLE>Net Bible - Genesis - 50</TITLE> for chapter 50. I think i need something like a wildcard to use here in the sed command. I just tried it without the <TITLE>Net Bible - Genesis </TITLE> line in the sed command and it still does not replace the text. I would be happy to send someone one of these htm files so you could see what i am talking about. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sunday 11 November 2007 10:58, Chris Arnold wrote:
There are a couple of reasons why this does not work. First and foremost: since your replacement text contains '/', you should use a text separator different from '/' like s#foo#bar#g
If I remember correctly < and > are also special (have to look that up) and you should escape them: \< and \>.
No. They're special to the shell, but since you'll surely quote the entire sed argument holding the editing command, that's not an issue. In fact, putting backslash before angle brackets gives them special meaning, namely word boundaries, left and right, for \< and \>, resp.
...
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Chris Arnold schreef:
There are a couple of reasons why this does not work. First and foremost: since your replacement text contains '/', you should use a text separator different from '/' like s#foo#bar#g
If I remember correctly < and > are also special (have to look that up) and you should escape them: \< and \>.
Finally, this would only work on a consecutive text without newlines and I think that is not what you have in mind.
Look up the c command in sed, because I think that is what you need. This lets you replace a couple of lines with a couple of other lines.
OK, i have looked up the c command nd run this command: sed -ic 's#<HTML><HEAD><TITLE>Net Bible - Genesis </TITLE><LINK REL=Stylesheet HREF="style.css" TYPE="text/css" MEDIA=screen></HEAD><body><p class=title>#<?php require('../../wp-blog-header.php'); ?><?php get_header(); ?><?php include(TEMPLATEPATH."/sidebar1.php");?><div id="main"><div id="content">#g' ./*
And this time, i do not get an error and i am left at the prompt. Then i check 1 of the files and nothing has been replaced. So, is my syntax for the c command in sed right (sed -ic)? I tried sed -c and got an invalid --c option. I wonder if some of the problem is that the <TITLE>Net Bible - Genesis </TITLE> line is different for every file. In other words, for the book of Genesis, for every chapter (every chapter is a new file), this line would read <TITLE>Net Bible - Genesis - 50</TITLE> for chapter 50. I think i need something like a wildcard to use here in the sed command. I just tried it without the <TITLE>Net Bible - Genesis </TITLE> line in the sed command and it still does not replace the text. I would be happy to send someone one of these htm files so you could see what i am talking about.
There's a difference between command and option. You use the -ic option (I don't know what that does, but obviously not what you want) and the s command. I suggest you do a read up on sed. Google "sed tutorial" and if all else fails type #sed in konquerors location bar. Regards, -- Jos van Kan registered Linux user #152704 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Chris Arnold wrote:
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code 2.rename the file to .php
Isn't there a program that will search all the files in a given directory for html and head and then replace that with something else?
No, but you can write a shell-script using the find command and use the -exec option
Then rename the files?
Do you mean the mv command?
I have seen the replace function in gedit but it does not accept the php code that needs to be inserted (i think the code is to long). Anyone no of a program/way that will accomplish this?
sed, the Stream EDitor Get the book "sed & awk" from O'Reilly books. Get away from the non-productive GUI and learn how to use the command line. That's where the power is. And don't tell me it's too hard... telephone company SECRETARIES were using it as far back as the 1970's. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Chris Arnold wrote:
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code 2.rename the file to .php
Isn't there a program that will search all the files in a given directory for html and head and then replace that with something else? Then rename the files? I have seen the replace function in gedit but it does not accept the php code that needs to be inserted (i think the code is to long). Anyone no of a program/way that will accomplish this?
Cannot help you with the first requirement but regarding renaming the files use XnView to do this. XnView is basically a picture viewing application but, surprisingly, it doesn't care what the files are when you use its Batch Rename facility - it will happily rename the extension of the files for you. Place all the html-extension files in the one directory then use the Batch Rename facility in XnView to rename the extenions to .php. Cheers. -- Past experience, if not forgotten, is a guide for the future. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
KDE KDevelop can make a mass-find&replace. KDE Krusader can change your file extensions. -- -Alexey Eremenko "Technologov" -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
thanks to Alexey Eremenko "Technologov" for opensuse for lizard esp on virtual box installation, i always fail in networking when i install from rpm / official package. then when try run installer for all distribution n follow the instruction on the user manual, the same, not work. to all users who wanna install the virtual box get the installater for all distro n follow the alexey book esp on installation section. br, tambun -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Nov 13, 2007 9:18 AM, chika <chika@cs.its.ac.id> wrote:
thanks to Alexey Eremenko "Technologov" for opensuse for lizard esp on virtual box installation,
i always fail in networking when i install from rpm / official package. then when try run installer for all distribution n follow the instruction on the user manual, the same, not work.
to all users who wanna install the virtual box get the installater for all distro n follow the alexey book esp on installation section.
I'm glad to hear that it helped to somebody ! Lately there is a boom of VirtualBox popularity :) BTW: It's not openSUSE for lizard, but it's "Lessons for Lizards" (LfL). It can be installed into 10.3 as offline help - Use Yast Software Manager, search and install "lessons4lizards" rpm. Then Start->Help->Lessons for Lizards. Both VirtualBox and my guide are integrated into openSUSE 10.3 OS. Best wishes, -- -Alexey Eremenko "Technologov" -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
sorry... for the name.... btw i have problem with seamless windows xp. i have uml-utilities installed, i've followed your instruction there. br0, tap0, eth0 set to none (aka no ip address). what should i do if on the guest i have xp then i wanna remote seamlessly from my susebox? n access samba server from the xp? can u give me the link reference? booming of virtualbox ... off course ... coz it is the better solution. br, tambun
On Nov 13, 2007 9:18 AM, chika <chika@cs.its.ac.id> wrote:
thanks to Alexey Eremenko "Technologov" for opensuse for lizard esp on virtual box installation,
i always fail in networking when i install from rpm / official package. then when try run installer for all distribution n follow the instruction on the user manual, the same, not work.
to all users who wanna install the virtual box get the installater for all distro n follow the alexey book esp on installation section.
I'm glad to hear that it helped to somebody ! Lately there is a boom of VirtualBox popularity :)
BTW: It's not openSUSE for lizard, but it's "Lessons for Lizards" (LfL).
It can be installed into 10.3 as offline help - Use Yast Software Manager, search and install "lessons4lizards" rpm. Then Start->Help->Lessons for Lizards.
Both VirtualBox and my guide are integrated into openSUSE 10.3 OS.
Best wishes, -- -Alexey Eremenko "Technologov" -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Basil Chupin wrote:
Chris Arnold wrote:
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code 2.rename the file to .php
Isn't there a program that will search all the files in a given directory for html and head and then replace that with something else? Then rename the files? I have seen the replace function in gedit but it does not accept the php code that needs to be inserted (i think the code is to long). Anyone no of a program/way that will accomplish this?
Cannot help you with the first requirement but regarding renaming the files use XnView to do this. XnView is basically a picture viewing application but, surprisingly, it doesn't care what the files are when you use its Batch Rename facility - it will happily rename the extension of the files for you.
Place all the html-extension files in the one directory then use the Batch Rename facility in XnView to rename the extenions to .php.
Cheers.
Doesn't Quanta plus have a function like this? -ED- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Ed McCanless wrote:
Basil Chupin wrote:
Chris Arnold wrote:
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code 2.rename the file to .php
Isn't there a program that will search all the files in a given directory for html and head and then replace that with something else? Then rename the files? I have seen the replace function in gedit but it does not accept the php code that needs to be inserted (i think the code is to long). Anyone no of a program/way that will accomplish this?
Cannot help you with the first requirement but regarding renaming the files use XnView to do this. XnView is basically a picture viewing application but, surprisingly, it doesn't care what the files are when you use its Batch Rename facility - it will happily rename the extension of the files for you.
Place all the html-extension files in the one directory then use the Batch Rename facility in XnView to rename the extenions to .php.
Cheers.
Doesn't Quanta plus have a function like this?
I absolutely have no idea. Leave it up to you to find out :-) . Cheers. PS. What is Quanta? -- Past experience, if not forgotten, is a guide for the future. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Hi all,
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code 2.rename the file to .php
I recommend rpl to replace strings in multiple files: http://fresh.t-systems-sfr.com/unix/src/privat2/rpl-1.4.0.tar.gz/ Changing the extension of a bunch of files is as easy as (/bin/sh): for i in *.html ; do mv $i `basename $i .html`.php done You need to be a fan of the command line, though ;). Rgds, Stephan. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
I recommend rpl to replace strings in multiple files: http://fresh.t-systems-sfr.com/unix/src/privat2/rpl-1.4.0.tar.gz/ I try this page and get a timeout in firefox2. Changing the extension of a bunch of files is as easy as (/bin/sh): for i in *.html ; do mv $i `basename $i .html`.php done You need to be a fan of the command line, though ;). No problems with the command line but after making a file called "rename" with the above code in it (rename file is located in the directory where i need to rename the files), i run ./rename and instead of the files being renamed they are just copied. So, 1file.htm has become 1file.htmc and every time i run rename it just adds a "c" to the end of the file name. So, 1file.htmc, if rename is run again, becomes 1file.htmcc -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Basil Chupin wrote:
Ed McCanless wrote:
Basil Chupin wrote:
Chris Arnold wrote:
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code 2.rename the file to .php
Isn't there a program that will search all the files in a given directory for html and head and then replace that with something else? Then rename the files? I have seen the replace function in gedit but it does not accept the php code that needs to be inserted (i think the code is to long). Anyone no of a program/way that will accomplish this?
Cannot help you with the first requirement but regarding renaming the files use XnView to do this. XnView is basically a picture viewing application but, surprisingly, it doesn't care what the files are when you use its Batch Rename facility - it will happily rename the extension of the files for you.
Place all the html-extension files in the one directory then use the Batch Rename facility in XnView to rename the extenions to .php.
Cheers.
Doesn't Quanta plus have a function like this?
I absolutely have no idea. Leave it up to you to find out :-) .
Cheers.
PS. What is Quanta?
OK, I refreshed my memory, as you subtly suggested. I could find no reference to running batch files in Quanta, but edit>find, edit> find next, and edit>replace provide a fairly quick way to do this type of work in Quanta plus. -ED- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Sunday 11 November 2007 01:41, Chris Arnold wrote:
I have a bunch of html files that i need to do a couple of things to: 1.remove the html and head tags and replace them with other code
perl -p -i -e 's/oldtext/newtext/' *.html
2.rename the file to .php
mmv "*.html" "#1.php" (you might have to install package mmv first) CU -- Stefan Hundhammer <sh@suse.de> Penguin by conviction. YaST2 Development SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Nürnberg, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Stefan Hundhammer wrote:
perl -p -i -e 's/oldtext/newtext/' *.html
/oldtext will be lines of html and /newtext will be lines of php. Will perl still be able to do it and if so, do i need to escape some of the code in oldtext and newtext? Example: <HTML> the < and > and <?php ;?> does any of that need to be escaped? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Chris Arnold wrote:
Stefan Hundhammer wrote:
perl -p -i -e 's/oldtext/newtext/' *.html
/oldtext will be lines of html and /newtext will be lines of php. Will perl still be able to do it and if so, do i need to escape some of the code in oldtext and newtext? Example: <HTML> the < and > and <?php ;?> does any of that need to be escaped?
Probably a little over the top but ... man perlrequick nand man perlretut will help... - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFHOWrEasN0sSnLmgIRAjEsAJ4oOAoKEEsGuEBX/vqS+Xi9b3ks6gCfZ37O F2EU35JlAg+7nUCdYIZXoNQ= =ESp3 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 12 November 2007 22:24, Chris Arnold wrote:
Stefan Hundhammer wrote:
perl -p -i -e 's/oldtext/newtext/' *.html
/oldtext will be lines of html and /newtext will be lines of php. Will perl still be able to do it and if so, do i need to escape some of the code in oldtext and newtext? Example: <HTML> the < and > and <?php ;?> does any of that need to be escaped?
I did some experimenting, and admittedly there are some caveats with that stuff. But here is a skeleton for you: perl -p -i -0777 \ -e 's/^.*<!DOCTYPE\s+html.*<body>/PHP-Header\n/si;' \ -e 's:</body>.*$:<?PHP-Footer?>\n:si;' \ -e 's:moreoldstuff:newoldstuff:g;' \ *.html Note: This is one single line of shell command. I just reformatted it for better legibility. Let's take this apart. perl -p : This reads the files specified on the command line as input files line by line and prints each single line. If you don't do anything else, this is a glorified "copy" command. But with regular search-and-replace, this becomes more like a "sed" call. Note there is also "perl -n" which does not print; you'd have to append 'p' ("print") to each regexp replace to write something to the output file, or use the regular perl "print" command. -i : This does all changes in-place, i.e. you don't need to supply an input and an output file. Otherwise you'd have to write your own loop in the shell and do something like perl -p -e'<do something>' <infile >outfile perl -i does that loop for you, reads from each infile from the command line, writes to a new file and renames the new file afterwards to the name of the infile. You can also specify a backup file extension: "perl -i.bak" will back up all old infiles to "infile.bak". -e : This specifies one perl expression. You can use several -e args, but then you need to delimit all (except the last one) with a semicolon. A bit unlike "sed", unfortunately. By default, perl reads one single line from the infile, processes it with all your -e expressions and (with -p) writes it to the outfile. This is what most people need in most cases. You can use that as a "sed" substitute with in-place editing - this is what I wrote in my first post to this thread: perl -p -i -e 's/oldstuff/newstuff/g' The '/g' at the end tells perl to do that globally, i.e., more than once. Otherwise it would just replace one single time. Just like "sed". In your special case, though, you want to search and replace over multiple lines. That's a bit tricker. For one thing, you need to tell perl to read more than just one line at a time. For example, the entire file at once. This is what -0777 does: It changes the input record delimiter from \n (newline) to character 0777 (octal) which doesn't exist, thus the entire file is read at once. (See "man perlrun"). Then, you also have to make perl match more than just one single line in a regular expression: s/oldstuff/morestuff/s Note that this is necessary in addition to having the whole file in one single string. I also added /i to match case-insensitive which makes sense for HTML tags. Quoting regular expressions is another tricky part. You have to watch carefully which characters in "oldstuff" have a special meaning in perl's (very powerful!) regular expressions. But typically that's not a problem because that part is hand-written, not variable stuff coming from a file. \s is useful: It's a shorthand for "any kind of whitespace character" - blank, tab, newline. "\s+" means "at least one whitespace character, but maybe more (any number)". In the replace text there are a lot less characters with special meaning. $1, $2, ... $9 come to mind; they are placeholders for an expression in parentheses in "oldstuff". If your search regexp contains slashes, it makes sense to use some other delimiter character; this is what I did in the other -e expressions: s:oldstuff/with/slashes:newstuff: You could also escape every single slash with a backslash, but that's tedious, error-prone and it looks ugly: s:oldstuff\/with\/slashes/newstuff/ Did I forget something? Probably. But hey, I don't want to deprive you of all intellectual challenges. ;-) I hope I gave you some good starting points, though. More info: man perlre (Perl regular expressions) man perlrun (Perl command line switches) man perlop (Perl quoting) CU -- Stefan Hundhammer <sh@suse.de> Penguin by conviction. YaST2 Development SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) Nürnberg, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (13)
-
Aaron Kulkis
-
Alexey Eremenko
-
Basil Chupin
-
chika
-
Chris Arnold
-
David Bolt
-
Ed McCanless
-
G T Smith
-
Jos van Kan
-
Michael Skiba
-
Randall R Schulz
-
Stefan Hundhammer
-
Stephan Hegel