Hold buffer in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Hold buffer in perl
# 1  
Old 03-22-2011
Hold buffer in perl

Hi,

Can any one tell me is their any "hold buffer" in perl similar to sed.

I have to find a pattern, once that pattern found then need to go backward and find another pattern and print.

Example:

Below are the contents present in a file
##
block
IPs
URLs
URL_IPs
Unblock
URLs

Script should search for "Unblock" pattern first and then go backward and find the "block" pattern and print "block" and "Unblock" patterns.

I know it how to do in sed. But i want it in perl.

Thanks
# 2  
Old 03-23-2011
Quote:
Originally Posted by Anjan1
...
Below are the contents present in a file
##
block
IPs
URLs
URL_IPs
Unblock
URLs
...
What is the desired output for the input file you posted (repeated below) ?

Code:
##
block
IPs
URLs
URL_IPs
Unblock
URLs

tyler_durden
# 3  
Old 03-27-2011
Sorry for the delay:

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 ----------

Can any one please post answer quickly
# 4  
Old 03-28-2011
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.
# 5  
Old 03-28-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting some part of Perl's Expect Buffer

Hi, I am capturing command's output on remote host using Expect. The problem is that the command line arguments also getting print with the output in file and also need to print last two relevant columns (percentage used and its mounted point). The output of $exp->before() buffer is :df... (1 Reply)
Discussion started by: suneet17
1 Replies

2. Shell Programming and Scripting

Variable hold in UNIX job

In log directory file contain log files and files contain some unique job name which is dynamically created (example=55555 ),if job get 55555 then send alert message, but after next run if it find ---55555 then no need send alert message While checking the first job name you are capturing the Job... (3 Replies)
Discussion started by: Kalia
3 Replies

3. Shell Programming and Scripting

Hold buffer in sed

Hi Experts, i have a file like below **** table name is xyz row count for previous day 10 row count for today 20 diff between previous and today 10 scan result PASSED **** table name is abc row count for previous day 90 row count for today 35 diff between previous and today 55... (4 Replies)
Discussion started by: Lakshman_Gupta
4 Replies

4. Shell Programming and Scripting

read is not on hold

In end of https://www.unix.com/shell-programming-scripting/103227-while-read-loop-scope-variables-shell.html mjd_tech gives script which can read some values directly without manually input, but if no value is the right one, my understand is, it will on hold for waiting the next input, but when I... (7 Replies)
Discussion started by: newoz
7 Replies

5. Shell Programming and Scripting

sed: hold buffer question

I've been using sed to help with reformatting some html content into latex slides using the beamer class. Since I'm new to sed, I've been reading a lot about it but I'm stuck on this one problem. I have text that looks like this: ******************* line of text that needs to be... (4 Replies)
Discussion started by: tfrei
4 Replies

6. Shell Programming and Scripting

What's the max integer a variable can hold?

I would like to know the maximum integer that a variable can hold. Actually one of my variable holds value 2231599773 and hence the script fails to process it.Do we have any other data type or options available to handle this long integers? (9 Replies)
Discussion started by: michaelrozar17
9 Replies

7. Shell Programming and Scripting

Hold previous date

A file named abc.txt being updated with date value by one process. Say , today it s updating the file with value 01-09-2009 Fine. Tomorrow the process will override the file with tomorrow date (02-09-2009) .Insome case the process will overriding the file with empty string. So I... (1 Reply)
Discussion started by: Gopal_Engg
1 Replies

8. UNIX for Dummies Questions & Answers

Determining which processes hold a semaphore

I have a situation where I have created a semaphore and set it's value to 10. I am using this semaphore to control access to a shared memory location. I can have 10 processes simultaneously read from the shared memory location, process 11 would get locked out. My question is, is there a way I... (6 Replies)
Discussion started by: tpotter01
6 Replies

9. Solaris

Kill a particular process if it's over an hour hold

I meant old not hold :) I need to kill a process if it's over an hour old and then send an e-mail of the list that was killed.....? I need to kill ps -ef | grep stashd | grep ' older than an hour?' #! /bin/bash if test ps -ef | grep <stashd> (Is over an hour old)???? >>stashd_old.txt ... (9 Replies)
Discussion started by: xgringo
9 Replies

10. UNIX for Dummies Questions & Answers

Support Needed: Education On Hold

I'm Presently Writting A College Report On Operating Systems, Not Enjoying It Very Much. I Was Hoping Someone Could Direct Me To A Site Where I Could Get Information Such As The Role Of Operating Systems, Types Of Operating Systems (Multi-User Multi-Tasking etc), Modes Of Operating systems... (3 Replies)
Discussion started by: OSNovice
3 Replies
Login or Register to Ask a Question