You are not logged in.
Pages: 1
Can someone help me with a sed string?
Basically what I want to run is: sed -i 's/<?/<?php/g' *.php
but it has trouble with the '<' characters and I've tried googling but can't for the life of me figure out how to parse this correctly
[home page] -- [code / configs]
"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol
Offline
My guess is that it is the ? character that is causing the problem. Haven't tested but "s#<\?#<\?php#" should get you close...
Offline
well, it ran successfully...
put '<?php' at the beginning of every single line tho haha
[home page] -- [code / configs]
"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol
Offline
\? is a special regex character. It matches 0-1 instances.
Definitely use ?
It changed (only) the beginning of every line because it didn't have the g option.
Same goes for \<. It is used to match words. But just < should work.
So I don't see anything wrong with your initial command. What was the error message?
Offline
oops....
it appears my sed-foo is weak
Offline
adding a 'g' onto the end replaces every single character with '<?php'
[home page] -- [code / configs]
"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol
Offline
anyone?
[home page] -- [code / configs]
"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol
Offline
adding a 'g' onto the end replaces every single character with '<?php'
Are you saying "every single character" literally? 'a' gets replaced with <?php, 'b' gets replaced with <?php, etc? Can you post an example of 1 file before and after? I just did some quick tests and sed -i 's/<?/<?php/g' *.php works fine for me to replace every occurrence of <? with <?php in a directory's .php files.
ARCH|awesome3.0 powered by Pentium M 750 | 512MB DDR2-533 | Radeon X300 M
The journey is the reward.
Offline
when I run the command you listed I get output like this
Last edited by Stythys (2008-10-28 01:59:40)
[home page] -- [code / configs]
"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol
Offline
wait...sorry creslin, I was running your command on my files after I already screwed them up, forgot to revert
and yeah your command worked, thanks. I'm almost certain that's what I was originally running....ah well
[home page] -- [code / configs]
"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol
Offline
yeah... the sed in your original looked fine.. /shrug
ARCH|awesome3.0 powered by Pentium M 750 | 512MB DDR2-533 | Radeon X300 M
The journey is the reward.
Offline
Pages: 1