Unix Shell - add content of 3 files to a template

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > February 2007 > add content of 3 files to a template





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author add content of 3 files to a template
mike

2007-02-19, 1:16 pm

Hi,

I have a Java source code template with header and some code at the
end (see below).
I need to add the content of three files in the middle of the file.

Is there a way I can find out which line '{' the character is and the
"include" the content of the three files on this line. Or is there a
better approach?

Cheers,

//mikael



/**
*
*
*
*
*/

public class Performance {


//Here I want to add the content of my three files


public static final int CONST1 = 1;
public static final int CONST2 = 2;
public static final int CONST3 = 3;

}

Janis Papanagnou

2007-02-19, 1:16 pm

mike wrote:
> Hi,
>
> I have a Java source code template with header and some code at the
> end (see below).
> I need to add the content of three files in the middle of the file.
>
> Is there a way I can find out which line '{' the character is and the
> "include" the content of the three files on this line. Or is there a
> better approach?
>
> Cheers,
>
> //mikael
>
>
>
> /**
> *
> *
> *
> *
> */
>
> public class Performance {
>
>
> //Here I want to add the content of my three files
>
>
> public static final int CONST1 = 1;
> public static final int CONST2 = 2;
> public static final int CONST3 = 3;
>
> }
>


One possibility (untested)...

{ awk '/^public static final int CONST1 = 1;/{exit}1'
cat file1 file2 file3
awk '/^public static final int CONST1 = 1;/,1'
} <oldfile >newfile


Another possibility is to feed commands to the ed editor...

echo $'/{/r file3\n/{/r file2\n/{/r file1\nwq' | ed template.java

(That works if it's the first and only curley brace in the file, which
might match your question. Otherwise you have to reposition the line
counter in ed before reading subsequent files.)

Janis
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com