2 added 106 characters in body
source | link

I have a file like this:-

pin(ABC) {
a b c d e f {
abc
}
}
pin(XYZ) {
g h i j k {
j k {
cg {
}
}
}
}
abcd pqrs rstu
mango banana tree
pin(PQR) {
mango
}

pin(ABC) {  
              a b c d e f {  
              abc  
              }  
             }  
pin(XYZ) {  
              g h i j k  {  
                      j k {  
                        cg {  
                     }  
                    }  
                   }  
                  }  
abcd pqrs rstu  
mango banana tree  
pin(PQR) {  
               mango  
         }  

Now i want to grep the text like this:-
when i give ABC as input then output should be a file named ABC with the content from "pin(ABC) {" upto matching bracket "}" like this :-

pin(ABC) {
a b c d e f {
abc
}
}

pin(ABC) {  
              a b c d e f {  
              abc  
              }  
             }  

when i give PQR the output should be a file named PQR with this content:-

pin(PQR) {
mango
}

pin(PQR) {  
               mango  
         }  

& so on for any word which is inside pin()
one way to do it is to grep the text from "pin(ABC" till next name "pin" & direct the output to the file named "ABC" , it works for only ABC but fails for case of PQR & XYZ. How to do it.

I have a file like this:-

pin(ABC) {
a b c d e f {
abc
}
}
pin(XYZ) {
g h i j k {
j k {
cg {
}
}
}
}
abcd pqrs rstu
mango banana tree
pin(PQR) {
mango
}

Now i want to grep the text like this:-
when i give ABC as input then output should be a file named ABC with the content from "pin(ABC) {" upto matching bracket "}" like this :-

pin(ABC) {
a b c d e f {
abc
}
}

when i give PQR the output should be a file named PQR with this content:-

pin(PQR) {
mango
}

& so on for any word which is inside pin()
one way to do it is to grep the text from "pin(ABC" till next name "pin" & direct the output to the file named "ABC" , it works for only ABC but fails for case of PQR & XYZ. How to do it.

I have a file like this:-

pin(ABC) {  
              a b c d e f {  
              abc  
              }  
             }  
pin(XYZ) {  
              g h i j k  {  
                      j k {  
                        cg {  
                     }  
                    }  
                   }  
                  }  
abcd pqrs rstu  
mango banana tree  
pin(PQR) {  
               mango  
         }  

Now i want to grep the text like this:-
when i give ABC as input then output should be a file named ABC with the content from "pin(ABC) {" upto matching bracket "}" like this :-

pin(ABC) {  
              a b c d e f {  
              abc  
              }  
             }  

when i give PQR the output should be a file named PQR with this content:-

pin(PQR) {  
               mango  
         }  

& so on for any word which is inside pin()
one way to do it is to grep the text from "pin(ABC" till next name "pin" & direct the output to the file named "ABC" , it works for only ABC but fails for case of PQR & XYZ. How to do it.

1
source | link

grep upto matching brackets

I have a file like this:-

pin(ABC) {
a b c d e f {
abc
}
}
pin(XYZ) {
g h i j k {
j k {
cg {
}
}
}
}
abcd pqrs rstu
mango banana tree
pin(PQR) {
mango
}

Now i want to grep the text like this:-
when i give ABC as input then output should be a file named ABC with the content from "pin(ABC) {" upto matching bracket "}" like this :-

pin(ABC) {
a b c d e f {
abc
}
}

when i give PQR the output should be a file named PQR with this content:-

pin(PQR) {
mango
}

& so on for any word which is inside pin()
one way to do it is to grep the text from "pin(ABC" till next name "pin" & direct the output to the file named "ABC" , it works for only ABC but fails for case of PQR & XYZ. How to do it.