Computing.Net > Forums > Programming > awk script issue

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

awk script issue

Reply to Message Icon

Name: neha_008
Date: May 28, 2009 at 02:48:37 Pacific
OS: AIX
Subcategory: Opinions
Comment:

I am having a big file having a subset of file content like this in a order
file

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

OR (P2) {

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

}

NAND (P3)

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

P1

LINE1

LINE2

P2

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




Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: May 28, 2009 at 03:48:31 Pacific
Reply:

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?


0

Response Number 2
Name: neha_008
Date: May 28, 2009 at 04:01:05 Pacific
Reply:

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)

Thanks
neha


0

Response Number 3
Name: neha_008
Date: May 29, 2009 at 06:47:16 Pacific
Reply:

Hi I am having one issue with my awk script
subset of my file content is

regexp LINE1 {
LINE2
LINE3

}

regexp LINE1 {

LINE6
LINE7

}

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


Thanks
neha


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: awk script issue

Shell commnd in awk script www.computing.net/answers/programming/shell-commnd-in-awk-script/13781.html

awk scripting using 2 input files www.computing.net/answers/programming/awk-scripting-using-2-input-files/17901.html

Awk script problem www.computing.net/answers/programming/awk-script-problem-/19228.html