LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-23-2005, 11:04 AM   #1
powah
Member
 
Registered: Mar 2005
Distribution: FC, Gentoo
Posts: 276

Rep: Reputation: 30
replace empty function from the old format to the new format


I have about 300 files which has the function getDBBackend().
How to write a program to change the empty function from the old format to the new format?

Old empty function format are either:
function getDBBackend()
{
// Not available
} // getDBBackend


or:
function getDBBackend()
{

} // getDBBackend


New empty function format is:
function getDBBackend()
{
// DB backend not applicable, use test backend
getTestObject();
} // getDBBackend


If the function is not empty, then it will not be changed:
function getDBBackend() {
$msg = db_start_dget(MIO_DGET_DATA);
//...
}
 
Old 07-10-2005, 01:02 PM   #2
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
I think it's easiest in python
Code:
oldform1 = "function getDBBackend()\n{\n ..."
oldform2 = """function getDBBackend()
{

} // getDBBackend"""
filenames = ["file1", "file2", ]
for fname in filenames:
 data = file(fname).read()
 data = data.replace(oldform1, newform)
 data = data.replace(oldform2, newform)
 file(fname, "w").write(data)
with appropriate values of filenames, oldform{1,2} and newform.

hth --Jonas
 
Old 07-10-2005, 02:18 PM   #3
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
sed
 
Old 07-11-2005, 05:06 PM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
to lowpro2k3:
sed struck me first too--but I can't seem to be able to do it in a fairly simple way (i.e. without stuffing lines into the holding space and doing nasty things with them there).

So if you have a script of about, say, 1-5 lines, please post it

--Jonas
 
Old 07-12-2005, 08:07 PM   #5
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
Talking

Agreed, I know it can be done but I'm far from slick enough to write a pretty one liner. It would be a mess of temp files that would work for me - ugly, but gets the job done
 
  


Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
format a hard drive (/dev/hda1) in Reiser fs format Linh Linux - General 7 06-17-2009 06:30 AM
Converting wma format to mp3 format. fakie_flip Linux - General 6 10-02-2005 07:49 PM
use vi to convert linux format to windows format intolinux Linux - Software 2 12-10-2003 10:20 PM
Format Problems Saving Star Office Docs in Word Format kkempter Linux - Software 4 08-27-2003 04:23 PM
About amiga format to linux format? 45pferde Linux - General 0 08-12-2001 07:06 PM


All times are GMT -5. The time now is 09:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration