Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am having a big file having a subset of file content like this in a order
fileAND (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

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?

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

Hi I am having one issue with my awk script
subset of my file content isregexp 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

![]() |
![]() |
![]() |

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