I need a quote for this please
Hi everyone,
I have several hundred .html files that have a mistake that I would like to fix. Can someone please help me with the code to do the change in all the files at once? I would hate to spend hours doing the change manually. Thank you. So, as an example, how would you change the following in all the files in the same directory? Before: <a href="http://www.googl.com">Google</a> After: <a href="http://www.google.com">Google</a> Thanks a million. |
I just realized that I put quote in the subject, I meant "code". I really don't want to change hundreds of files manually, I can barely type a correct subject line. :o)
|
This may work (you are advised to test it yourself before running it on real files, though):
Code:
for file in `ls *` |
Quote:
Code:
for file in $(ls -1 *.html) |
Thanks a lot to both of you. I'll test these out when I get home tonight.
|
I have one more request...been searching for a solution to this on the net, but couldn't find a solution that matched my problem exactly.
The problem is that I have a few hundred files in the same directory. I would like to change a part of their names. So I would like to change: My-Super-File-Name.html To: My-Great-File-Name.html Can you please tell me how this is done? Thanks in advance. |
Quote:
Code:
rename 's/Super/Great/' * |
wonderful, thank you. I am on Vector Linux and it seems like rename works differently here:
rename Super Great *.html Thanks again. |
ARRRGHHHH, the original code doesn't work. I guess the example that I gave was not exactly right. Here's the exact code that I want to change inside my file:
<h1><a href="#">The one and only</a></h1> To: <h1>The one and only</h1> I guess the slashes are throwing sed off, because I get an error. How do I do this? Thanks again. |
Quote:
Code:
sed -i 's/\(<h1>\)\(<a[^>]*>\)\([^<]*\)\(<\/a>\)\(<\/h1>\)/\1\3\5/' $file Code:
sed -i 's!\(<h1>\)\(<a[^>]*>\)\([^<]*\)\(</a>\)\(</h1>\)!\1\3\5!' $file |
Thank you Rob, but to be honest, to me, this is like Chinese mixed in with some English. What should I be studying to learn these stuff? Bash programming?
Anyhow, I ran the following command and got an error. Code:
root:# for file in 'ls *.html' |
I know what you mean - I often refer to these patterns as an explosion in a punctuation factory. They are called regular expressions, and consist of literal characters and metacharacters. The pattern means:
Code:
! Delimiter beginning search pattern The reason you got the error message is that you used single quotes - '...' - rather than backticks -`...` around the ls command in the first line - very easy to do. Backticks are on the key to the left of the 1 on a US/UK keyboard, but I would tend to use $(ls *.html) - the $(...) does the same thing as the backticks, but is a lot easier to read. Edited to add: slight warning about the documentation on regular expressions - there are different forms. For instance, in the link above, it tells you parentheses -- ( ) -- enclose a group. However, in the sed version, escaped parentheses - \( \) - are used. |
Wow, thank you so much Rob for helping me learn this stuff.
I'll try the command again shortly. Right now I got to get some dinner. Peace and thanks again. |
Quote:
This is why I always use $(command) instead of `command` it's easier to read (besides...using ` is deprecated...) Try it this way... Code:
root:# for file in $(ls *.html) |
Thank you so much everyone, this worked and saved me HOURS of time! So great, thank you!
|
Quote:
|
Just a small fyi; each lang that processes 'regexes' uses an internal 'regex engine'. However, each regex engine tends to be different to other regex engines, to a larger or smaller degree.
See for example http://regex.info/ IOW, regex 'incantations' may or may not(!) be transferable... YHBW... |
Quote:
|
All times are GMT -5. The time now is 02:52 AM. |