LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 08-22-2014, 05:14 AM   #1
drele
LQ Newbie
 
Registered: Feb 2011
Posts: 13

Rep: Reputation: 0
Need to replace function with another one, which has same name


for example I have to files. file1 and file2.
file1 and file2 consist of shell code blocks, which have functions and all sort of special characters.

So I wan't to replace all function and its content from file1 with same function and all their content of file2.

I used sed with that, but I am unable to execute properly sed because of special characters escaping which gives me truble.

Anyone has soulution?
 
Old 08-22-2014, 10:57 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Examples of what you have tried and what the data looks like would be extremely helpful.
 
Old 08-22-2014, 12:19 PM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
All you have to do is re-declare the function with the new code. The last declared code is what gets used/saved:
Code:
a () { echo a; } 
a () { echo b; }
a
 
  


Reply

Tags
functions, replace, sed



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
Conditionally replace nth column of every function call pravint Programming 2 07-08-2014 03:44 AM
[Help] Update mysql table with replace function with regular expression ubungu Linux - Software 1 07-10-2013 02:51 AM
Find Replace function in C++ somshridhar Programming 16 12-26-2011 08:46 AM
Need help to create a basic search and replace function. str1fe Linux - Newbie 4 01-11-2010 01:05 PM

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

All times are GMT -5. The time now is 01:26 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