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.
-A
option, which can specify how many lines to show after the match - this does have the problem that you need to know how many lines that need to be shown.