Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 30th, 2006, 12:11 PM   #1
karamelos
Newbie
 
Join Date: Apr 2006
Posts: 2
Rep Power: 0 karamelos is on a distinguished road
Read,regexp,rename,and save

Dear sirs

I am looking for a rename utility , but since now i wasn't able to find some for my needing

I have 500 .html files and i need to rename them based a search string inside the html files..more detailed, i need somethink like that:

1. Open the first .html file
2. Search for '<font size=+2>text example</font>' ( search for specific tag)
3. save the file as "text example.html" (found from tag result)
4. Go to the next .html file and repeat the same.

is there any utility on internet that make such a think ? or i have to make perl code?

Thanx a lot.

Panos
karamelos is offline   Reply With Quote
Old Apr 30th, 2006, 11:03 PM   #2
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
Try something like this - my regex is very probably wrong because your example seems contrived, so change it.

#!/bin/ksh
for file in `ls -1 *.html
do
    newname=$(perl -e ' 
               undef $/;
               $text=<>;
               $text~="{([A-Za-z ]+)</font>$}";
               print "$1;" ' "$file" )
    mv "$file" "$newname"
done

Test this first
jim mcnamara is offline   Reply With Quote
Old May 1st, 2006, 9:18 AM   #3
karamelos
Newbie
 
Join Date: Apr 2006
Posts: 2
Rep Power: 0 karamelos is on a distinguished road
My friend you are my hero..
If your code does save from what they found then is what exactly i need..
i wan't to search for a string <font>blahblah</font>
and i wanna save the .html file as blahblah , but in each file the content of <font>....</font> is different .. i hope that you gave me to work.

Thank you for the post..
karamelos is offline   Reply With Quote
Old May 3rd, 2006, 8:37 AM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
#!/bin/ksh
for file in `ls -1 *.html`
do
    newname=$(perl -e ' 
               undef $/;
               $text=<>;
               $text~="{([A-Za-z ]+)</font>$}";
               print "$1"; ' "$file" )
    mv "$file" "$newname"
done

Corrected two minor syntax errors - sorry.
jim mcnamara is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:36 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC