separating part of code from the program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting separating part of code from the program
# 1  
Old 06-12-2011
MySQL separating part of code from the program

hello sir,
i hav the program
Code:
void main()
{
int a,b,c
....
}
void insert()
{
int i;
...
}
void search()
{
int n
...
}

can i know how to seperate these functions individually and store them in separate files
ex
in file1
void main()
{
int a,b,c
....
}


in file 2
void insert()
{
int i;
...
}

in file3
void search()
{
int n
...
}


can someone suggest me the way to do this...
thank u in advance..Smilie
# 2  
Old 06-12-2011
Most simply put:

main.c:
Code:
#include <stdio.h>

int main()
{
  int a,b,c;
  a = insert();
  b = search();
  printf( "Insert: %d   -  Search: %d\n", a, b );
  return 0;
}

insert.c:
Code:
int insert()
{
  int i;
  return 1;
}

search.c:
Code:
int search()
{
  int n;
  return 2;
}

Code:
$ cc -o main main.c insert.c search.c
$ ./main
Insert: 1   -  Search: 2

# 3  
Old 06-12-2011
assume that your file is called t.txt, and each function has only one (the last one closing the function) "}":

Code:
 sed -r 's/\}/\}-----/g' t.txt|awk 'BEGIN{FS="-----";RS=""} {for (i=1;i<NF;i++){print $i > "file"i".txt"}} '

the command above will generate 3 files: file1-3.txt.
# 4  
Old 06-12-2011
Quote:
Originally Posted by sk1418
assume that your file is called t.txt, and each function has only one (the last one closing the function) "}":

Code:
 sed -r 's/\}/\}-----/g' t.txt|awk 'BEGIN{FS="-----";RS=""} {for (i=1;i<NF;i++){print $i > "file"i".txt"}} '

the command above will generate 3 files: file1-3.txt.
Ha ha. Thanks. I somehow feel I misinterpreted the question Smilie
# 5  
Old 06-12-2011
thank u so much for the reply..Smilie

---------- Post updated at 11:15 AM ---------- Previous update was at 11:14 AM ----------

i have one more query

I have two files def1.txt and def2.txt.
The contents of def1.txt are variables a,b and
the contents of def2.txt are variables i,a.
I need to perform intersection on these two files, i.e i should get the output file which contains variable a.
can u pls help me out..Smilie
# 6  
Old 06-12-2011
please give an example, what in the two input files, and how the output file should look like.
# 7  
Old 06-12-2011
MySQL intersection of contents in file

i hav two files
1.txt
//contents
a,b
c
d



2.txt
//contents
i,n
a
e,c

the expected output is
a,c

can u help me out in finding this..?
thank u..Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Figure out what rpm package a program is a part of

I am trying to figure out what rpm package a program is a part of. I have tried the normal way. rpm -qa | grep -i programname What other ways can you try? (3 Replies)
Discussion started by: cokedude
3 Replies

2. Shell Programming and Scripting

Help in separating a multilingual file

Hello, I have a text file running into around 100 thousand+ lines which has the following rigid structure: Each field is separated by a comma. Some examples are given below: 23,Chinttaman Pagare,चिंतमण पगारे 24, Chinttaman Pateel,चिंतामण पाटल 25, Chinttaman Rout,चिंतामण राऊत 26,... (3 Replies)
Discussion started by: gimley
3 Replies

3. Shell Programming and Scripting

How to execute a part of code at particular time

I had to execute the following code at 10:00 AM if then echo "Job done"; fi But this is not the entire piece of code, this is sub part of code which alone is to be executed at 10:00 AM, could anyone help me with this? (1 Reply)
Discussion started by: kishore kumar
1 Replies

4. Shell Programming and Scripting

Need help separating a file

Hi all, I have a single text file, Contig3.fasta, that looks like this: >NAME1 ACCTGGTA >NAME2 GGTTGGACA >NAME3 ATTTTGGGCCAnd It has about 100 items like this in it. What I would like to do is copy each item into 100 different text files, and have them named a certain way Output... (4 Replies)
Discussion started by: repiv
4 Replies

5. Shell Programming and Scripting

separating folders

I have folder like main. inside main folder there are subfolders & files like main1 main2 main3, file1, file2, file3. I want folders main1 & main2, file1, file2 from main folder. copy them into new folder. Please suggest me how to do it. I am new to shell programming (2 Replies)
Discussion started by: ypremcha
2 Replies

6. Shell Programming and Scripting

Separating fields

Hi, I have a text file in following format: 2.45 5.67 6.43 I have to cut the values before decimal and store them in a file. So the output file should look like: 2 5 6 . . and so on... Can someone suggest me a sed/awk command for doing this? (2 Replies)
Discussion started by: sajal.bhatia
2 Replies

7. Programming

Separating commands/programs with ;

Hi i have encountered a problem and i have tried many different things but my brain just has some limitations lol well anyways i was trying to make this program work down below so i can process multiple commands just by separating them with ;. I would apeciate if someone could just make it work kuz... (2 Replies)
Discussion started by: dush_19
2 Replies

8. Shell Programming and Scripting

separating fields

Hi, i have a file as follows: jonathan:bonus1,bonus2 gerald:bonus1 patrick:bonus1,bonus2 My desired output is jonathan:bonus1 jonathan:bonus2 gerald:bonus1 patrick:bonus1 patrick:bonus2 my current code is cat $F | awk -F"" how should i continue the code? Can i do something... (5 Replies)
Discussion started by: new2ss
5 Replies

9. Programming

separating commands

hey there well i have a small problem with my code. when for example : " /bin/sleep 10 & ls -l mila > xyz " is entered, the program is supposed to separate the two commands 1) /bin/sleep 10 & and 2) ls -l mila > xyz. im not sure of how to achieve this. my current program stores both commands... (2 Replies)
Discussion started by: mile1982
2 Replies
Login or Register to Ask a Question