LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 01-04-2016, 08:39 AM   #1
victorcheung
LQ Newbie
 
Registered: Jun 2015
Posts: 3

Rep: Reputation: Disabled
how to add string to file if pattern match


Hi,

I have a number of files with contents in the following format:

Class ABC
{ ...
function getname(userid)
{
...
...
}

function getprice(itemid,colorcode)
{
...
...
}
}

and I want to add test points to the files to check if the function has been called, so, the new file should look like, assume the file name for this example is /var/www/html/test.php:

Class ABC
{ ...
function getname(userid)
{
echo /var/www/html/test.php getname(userid) is called
...
}

function getprice(itemid,colorcode)
{
echo /var/www/html/test.php getprice(itemid,colorcode) is called
...
}
}


The "echo <file name> <function name> is called" is to be added to the beginning of each function in the file.


How to do that?
please help!

Thank you very much!
Victor
 
Old 01-04-2016, 09:29 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,658

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by victorcheung View Post
Hi,
I have a number of files with contents in the following format:

The "echo <file name> <function name> is called" is to be added to the beginning of each function in the file.

How to do that? please help!
Why don't you start by looking at your OTHER THREAD, where you asked a very similar question months ago?
http://www.linuxquestions.org/questi...ne-4175546506/

Try applying what you were told, and what you learn, and again, read the "Question Guidelines" link in my posting signature. When asking such things, YOU have to show us YOUR OWN EFFORTS, and what YOU have tried, rather than just asking for a handout.

If you need to loop through a bunch of files, again, there are MANY bash-scripting tutorials you can easily find. Show us what you have done/tried, and we can help you with problems.
 
1 members found this post helpful.
  


Reply



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
[SOLVED] Flow control based on grep match pattern or string 123raajesh Linux - Newbie 2 10-30-2013 06:40 AM
How to use Vi to match a string of text, add a new line, insert string... Slycraft Linux - Newbie 7 07-20-2012 10:24 AM
How to match for a pattern in a string using tcl kamesp Linux - Software 1 06-08-2012 04:58 PM
how to match for multiple pattern at the end of given string Santoshkb Programming 2 06-23-2008 10:42 AM
How to delete the file using pattern match? nishanthhampali Programming 3 04-16-2008 12:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration