Reputation: 197
i have a sed command to extract binding state free; block of data but this is giving output of binding state active block as well because same keyword in that block also with next and rewind keyword is there any way to match exact keyword for binding state free so that i can get only given block in sed command.
lease {
*****some text******
binding state free;
*****some text******
*****some text******
}
lease {
*****some text******
*****some text******
binding state free;
*****some text******
*****some text******
}
lease {
*****some text******
*****some text******
binding state active;
next binding state free;
rewind binding state free;
*****some text******
*****some text******
}
lease {
*****some text******
*****some text******
binding state active;
next binding state free;
rewind binding state free;
*****some text******
*****some text******
}
sed -n '/lease/!b;:a;/}/!{$!{N;ba}};{/binding state free;/p}' file.txt
Upvotes: 1
Views: 84
Reputation: 133428
Following awk
may help you in same.
awk '/}/{if(flag){print value ORS $0};flag=val=value="";next} /lease/{val=1} val && /^ +binding state free;/{flag=1} {value=value?value ORS $0:$0}' Input_file
Adding a non-one liner form of solution too now.
awk '
/}/{
if(flag){print value ORS $0};
flag=val=value="";
next}
/lease/{
val=1}
val && /^ +binding state free;/{
flag=1}
{
value=value?value ORS $0:$0}
' Input_file
Output will be as follows.
lease {
*****some text******
binding state free;
*****some text******
*****some text******
}
lease {
*****some text******
*****some text******
binding state free;
*****some text******
*****some text******
}
Upvotes: 1