I want to search for Unblock first and then go back and find for "block" pattern
say content of file is:
block 2010.5
IPs
URLs
URL_IPs
URLs
block 2010.6
IPs
URLs
URL_IPs
Unblock
URLs
Check for "unblock" pattern, if "unblock" pattern is their, then go back(move to the previous lines) and search if "block" pattern is their. If block patten exist, then print the first "block" pattern.
Output should be: block 2010.6
---------- Post updated at 01:31 PM ---------- Previous update was at 01:00 PM ----------
there is no concept of hold buffer in perl. you cannot directly replace sed with perl... Learn perl RE basics such as substituion, default variables and back references.
No need to "go back". On your line-by-line sweep store the line when you find "block", then print what you stored when you encounter "Unblock".
In perl you have as many hold buffers as you need -- variables.