[opensuse] SED help
Using SLED SP1 and SED. I need to add some text before some existing text in 1 file, in about 100 different spots. The existing text is as follows: <A onclick="window.open(this.href,'_blank');return false;" HREF='/kjvdict/indexFRMB01C001.htm'>1</A> The section of text above will differ in every line. So the section indexFRMB01C001 will appear as indexFRMB01C002 on the next line and so on for all 100 lines. Randall S wrote a killer script that would add quotes to some text so i am trying to modify that script and use it but not having much luck. Here is the script: #!/bin/sh targetList=( # ... or "ls": $( ls *.php ) ) for target in "${targetList[@]}"; do sed \ --in-place= \ -e "1s;*.htm;'&';" \ "$target" done You can see that i am trying to use a wildcard in *.htm......Clearly, i don't know what i am doing :) Can someone (nicely) help me with this? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Open the file in Kate and do a search and replace on the string indexFRMB01C001 and replace it with indexFRMB01C002 You don't need a script to do this at all. This is basic functionality in every text editor I have used for the past 10-15 years Cheers Todd Systems Administrator --------------------------------------------- Soho VFX - Visual Effects Studio 99 Atlantic Avenue, Suite 303 Toronto, Ontario, M6K 3J8 (416) 516-7863 http://www.sohovfx.com --------------------------------------------- On Dec 10, 2007, at 3:54 PM, Chris Arnold wrote:
Using SLED SP1 and SED. I need to add some text before some existing text in 1 file, in about 100 different spots. The existing text is as follows: <A onclick="window.open(this.href,'_blank');return false;" HREF='/ kjvdict/indexFRMB01C001.htm'>1</A>
The section of text above will differ in every line. So the section indexFRMB01C001 will appear as indexFRMB01C002 on the next line and so on for all 100 lines. Randall S wrote a killer script that would add quotes to some text so i am trying to modify that script and use it but not having much luck. Here is the script:
#!/bin/sh targetList=(
# ... or "ls": $( ls *.php ) )
for target in "${targetList[@]}"; do
sed \ --in-place= \ -e "1s;*.htm;'&';" \ "$target"
done
You can see that i am trying to use a wildcard in *.htm......Clearly, i don't know what i am doing :) Can someone (nicely) help me with this? -- 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
Open the file in Kate and do a search and replace on the string indexFRMB01C001 and replace it with indexFRMB01C002 I don't need to do a "replace". I need to add some text before the indexFRMB01C00?
On Dec 10, 2007, at 3:54 PM, Chris Arnold wrote:
Using SLED SP1 and SED. I need to add some text before some existing text in 1 file, in about 100 different spots. The existing text is as follows: <A onclick="window.open(this.href,'_blank');return false;" HREF='/ kjvdict/indexFRMB01C001.htm'>1</A>
The section of text above will differ in every line. So the section indexFRMB01C001 will appear as indexFRMB01C002 on the next line and so on for all 100 lines. Randall S wrote a killer script that would add quotes to some text so i am trying to modify that script and use it but not having much luck. Here is the script:
#!/bin/sh targetList=(
# ... or "ls": $( ls *.php ) )
for target in "${targetList[@]}"; do
sed \ --in-place= \ -e "1s;*.htm;'&';" \ "$target"
done
You can see that i am trying to use a wildcard in *.htm......Clearly, i don't know what i am doing :) Can someone (nicely) help me with this? -- 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 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Dec 10, 2007, at 4:49 PM, Chris Arnold wrote:
Open the file in Kate and do a search and replace on the string indexFRMB01C001 and replace it with indexFRMB01C002
I don't need to do a "replace". I need to add some text before the indexFRMB01C00?
then do a search on indexFRMB01C00 and replace it with
On Dec 10, 2007, at 4:49 PM, Chris Arnold wrote:
then do a search on indexFRMB01C00 and replace it with
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
* Chris Arnold
Open the file in Kate and do a search and replace on the string indexFRMB01C001 and replace it with indexFRMB01C002 I don't need to do a "replace". I need to add some text before the indexFRMB01C00?
sameo, sameo find: indexFRMB01C001 replace: [some-text]indexFRMB01C001 PLEASE, trim your quotes. Thank-you, - -- Patrick Shanahan Plainfield, Indiana, USA HOG # US1244711 http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2 Registered Linux User #207535 @ http://counter.li.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFHXbhBClSjbQz1U5oRAnBsAJ9VFBiRFsmYp673rKuamx2RmnP0BQCfcRvW ULOhn3/vt2sAgXHA4SLLsUY= =a3Cn -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Chris Arnold wrote:
Open the file in Kate and do a search and replace on the string indexFRMB01C001 and replace it with indexFRMB01C002
I don't need to do a "replace". I need to add some text before the indexFRMB01C00?
Oh, sorry I went straight to the script and didn't read your message very well. To do this, use the sed command sed --in-place= -e "s/\(\/[^\.\/]*\)\(\.htm\)/\1YOURTEXT\2/" "$target" this assumes no lines end in the middle of your HREF filenames. Replace YOURTEXT with what you want. --Jason
On Dec 10, 2007, at 3:54 PM, Chris Arnold wrote:
Using SLED SP1 and SED. I need to add some text before some existing text in 1 file, in about 100 different spots. The existing text is as follows: <A onclick="window.open(this.href,'_blank');return false;" HREF='/ kjvdict/indexFRMB01C001.htm'>1</A>
The section of text above will differ in every line. So the section indexFRMB01C001 will appear as indexFRMB01C002 on the next line and so on for all 100 lines. Randall S wrote a killer script that would add quotes to some text so i am trying to modify that script and use it but not having much luck. Here is the script:
#!/bin/sh targetList=(
# ... or "ls": $( ls *.php ) )
for target in "${targetList[@]}"; do
sed \ --in-place= \ -e "1s;*.htm;'&';" \ "$target"
done
You can see that i am trying to use a wildcard in *.htm......Clearly, i don't know what i am doing :) Can someone (nicely) help me with this? -- 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
Chris Arnold wrote:
Open the file in Kate and do a search and replace on the string indexFRMB01C001 and replace it with indexFRMB01C002 I don't need to do a "replace". I need to add some text before the indexFRMB01C00?
the following inserts BAR before every occurrance of foo: s/foo/BARfoo s is for substitute, i.e. replace.
On Dec 10, 2007, at 3:54 PM, Chris Arnold wrote:
Using SLED SP1 and SED. I need to add some text before some existing text in 1 file, in about 100 different spots. The existing text is as follows: <A onclick="window.open(this.href,'_blank');return false;" HREF='/ kjvdict/indexFRMB01C001.htm'>1</A>
The section of text above will differ in every line. So the section indexFRMB01C001 will appear as indexFRMB01C002 on the next line and so on for all 100 lines. Randall S wrote a killer script that would add quotes to some text so i am trying to modify that script and use it but not having much luck. Here is the script:
#!/bin/sh targetList=(
# ... or "ls": $( ls *.php ) )
for target in "${targetList[@]}"; do
sed \ --in-place= \ -e "1s;*.htm;'&';" \ "$target"
done
You can see that i am trying to use a wildcard in *.htm......Clearly, i don't know what i am doing :) Can someone (nicely) help me with this? -- 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
On Mon December 10 2007 05:48:47 pm Aaron Kulkis wrote:
the following inserts BAR before every occurrance of foo:
s/foo/BARfoo
's/foo/BARfoo' only substitutes the first occurrance of 'foo'. Append the 'g'lobal flag to replace all occurrances, i.e.: s/foo/BARfoo/g' regards, Carl -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Chris Arnold wrote:
Using SLED SP1 and SED. I need to add some text before some existing text in 1 file, in about 100 different spots. The existing text is as follows: <A onclick="window.open(this.href,'_blank');return false;" HREF='/kjvdict/indexFRMB01C001.htm'>1</A>
The section of text above will differ in every line. So the section indexFRMB01C001 will appear as indexFRMB01C002 on the next line and so on for all 100 lines. Randall S wrote a killer script that would add quotes to some text so i am trying to modify that script and use it but not having much luck. Here is the script:
#!/bin/sh targetList=(
# ... or "ls": $( ls *.php ) )
for target in "${targetList[@]}"; do
sed \ --in-place= \ -e "1s;*.htm;'&';" \ "$target"
done
You can see that i am trying to use a wildcard in *.htm......Clearly, i don't know what i am doing :) Can someone (nicely) help me with this?
You need to use regular expression syntax for wildcards. The dot (.) character represents almost any character (newlines depending on settings) and star represents 0 or more instances, so .*\.htm is the regular expression syntax for the more familar form of *.htm that you are thinking of. The backslash escapes the dot so \. means the actual dot (period) character. I'm not too familiar with sed but I imagine that this command sed -i -e "s/.*\.htm/\&" file will probably do what you want. -i is short for --in-place. Note that .* greedily matches characters, except for new line, so this is only going to match the first ".htm" it finds on a line. If you might have more than one per line, you need to find some way to delineate the toke, maybe if it is surrounded by whitespace or a quote or something. Also note that the & character by itself will reference the matched text, and the escaped & (\&) will be the actual & character, I assume that's what you wanted. I'm not sure of the semicolon syntax you have used, thus i have replaced the semicolons with the standard forward slashes. --Jason -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday 10 December 2007 13:45, Jason Craig wrote:
Chris Arnold wrote: ... I'm not sure of the semicolon syntax you have used, thus i have replaced the semicolons with the standard forward slashes.
In the original sample script I wrote for Chris, there were slashes in the target and / or replacement text, so I illusrated the technique of using an alternate separator character to avoid having to escape that character when you need to include it in the pattern or replacement.
--Jason
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
On Monday 10 December 2007 13:45, Jason Craig wrote:
In the original sample script I wrote for Chris, there were slashes in the target and / or replacement text, so I illusrated the technique of using an alternate separator character to avoid having to escape that character when you need to include it in the pattern or replacement.
My bad, I checked out sed's man pages and now I know; it will accept a variety of delimiters! :) --Jason -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Aaron Kulkis
-
Carl Hartung
-
Chris Arnold
-
Jason Craig
-
M. Todd Smith
-
Patrick Shanahan
-
Randall R Schulz