Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
how to edit multiple files at a time?
Old 06-06-2005, 04:12 AM how to edit multiple files at a time?
gdhanasekar's Avatar
Banned

Posts: 20
Trades: 0
Hello all,

I want to know the some programs details regarding following ....

1. how to edit the many files concurrently
(Example: Suppose I have 500 html files, I want to insert the one line like keywords, tag line ( this should be same ) etc... in the all html files.)
is there any software or anyone willing to writing code for this one (using java, c lang's)

2. how to save a same file content into a multiple files with other names

(Example: Suppose I have a htlml file(same content for all webpages) , in that file i want to modify only the links, and i want to save as a newfile with naming like1.html 2.html 3.html etc in a sequential manner)

is there any software or anyone willing to writing code for this one (using java, c lang's)

Note: html file int the sence only txt files(src code for html page)


thanks
gdhanasekar is offline
Reply With Quote
View Public Profile Visit gdhanasekar's homepage!
 
 
Register now for full access!
Old 06-06-2005, 10:23 AM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Well first of all your scenario sounds dreadfull (Today I am glad I aint you)

Secondly you are in luck

Thirdly you might be out of luck.

What OS are you running? Do you have access to PERL?

If you dont have PERL or your not using nix then i cannot help otherwise read away.

Under nix we have a utility named Grep, Grep is a pattern matching binary that will probe files for a pattern. However we can also use it smartly to find say a blank line then add our new line to it.

So something like

perl -p -i -e 's/pattern/<replace>/g' `grep -rI pattern * | awk -F : '{print $1 }' | sort | uniq | xargs`

Would for each file in <location> be parsed and any patterns matching would be replaced.

So hang on you say what when how where ?????????????

To add your extra line search for a distinct tag like

perl -p -i -e 's/<head>/<head>\n<link rel="..">/g' `grep -rI head * | awk -F : '{print $1 }' | sort | uniq | xargs`

Which now polls all files in <location> finds the <head> tag and replaces it with <head> + <link rel=""> or whatever you wanna insert. And yes this will do it for all files and directories within your initial directory.

And low and behold your up and running in no time at all.

Of course if you are running windows then (tough, get a real OS) I cannot help for gawd only knows how you would do this under windows.

How to save same file content to multiple files.

Do these files exist?

NO

for i in `seq 20`
do
echo pattern > $i.txt
done

do they already exists?

If not valid remove and apply above.
else
for file in * do
echo pattern > $file
done

Of course nix excells at this kind of thing whereas I have no idea how Windows would start to resolve this problem.

And no if your using windows I will not take you files and do it for you.

Good luck
Ibbo

PS
I can explain whats happening if anyone should really like to know but you can take my word for it, this WORKS.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf

Last edited by ibbo; 06-06-2005 at 10:26 AM..
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Reply     « Reply to how to edit multiple files at a time?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15885 seconds with 12 queries