awk script issue

May 28, 2009 at 02:48:37
Specs: AIX
I am having a big file having a subset of file content like this in a order

AND (P1) {
no : and ;
mo : band ;
co : land ;

OR (P2) {

no : sand ;
cling : dad ;
Fiend : salt ;



no : sat ;
to : jat;
pi : tad;

I need to Insert the content of another file in this file before the Block AND (P1)

The script should search the AND (P1) and insert the content of another file before this Blocks

Another file content : file2





I am using following awk script

awk '{ if($0 ~ /P1/) {set=1; next}; if( $0 ~ /P2/) {set = 0}; if (set ) { print }}' file2 | awk '/AND (P1)/{f=1}f && /}/{print; system("cat $1");f=0;next}1' file > newfile

But I need to put the content before the Block AND (P1) which this script is not doing

Please help me out in this

See More: awk script issue

Report •

May 28, 2009 at 03:48:31
you have this similar problem somewhere else right? why don't you ask again the person who provided you the code how to do it?

Report •

May 28, 2009 at 04:01:05
Hey ! I have figured it out .The moderator of that Forum is not interested to help the new guys like me .I did not get the satisfactory reply thats why I asked the Question.

awk '{if($0 ~ /P1/) {set=1; next }; if( $0 ~ /P2/) {set = 0} ; if (set ) { print }}' insert_code_modify | awk '/AND (P1)/{print g; system("cat $1")}1' 1.lib > newfile

The above script is working fine but Globally it is not inserting the code

If I am having three Blocks of AND (P1) and it has to insert the code everytime it searches the AND (P1)


Report •

May 29, 2009 at 06:47:16
Hi I am having one issue with my awk script
subset of my file content is

regexp LINE1 {


regexp LINE1 {



I need to search the pattern regexp LINE1 The script after matching the regexp LINE1 will leave the first Block and delete the second Block


Report •

Related Solutions

Ask Question