Sponsored Content
Top Forums Shell Programming and Scripting look for two consecutive lines in all text files Post 302450354 by albertkao on Thursday 2nd of September 2010 12:07:59 PM
Old 09-02-2010
look for two consecutive lines in all text files

How to get (a list of) all the text files in the current directory and subdirectories which has the following two consecutive lines:
ctrl_end_date=2009
ctrl_process=EXPIRED
OR
ctrl_end_date=2010
ctrl_process=EXPIRED

i.e.
(ctrl_end_date=2009 OR ctrl_end_date=2010)
AND
ctrl_process=EXPIRED

---------- Post updated at 11:07 AM ---------- Previous update was at 10:41 AM ----------

a related question:
How to get (a list of) all the text files in the current directory and subdirectories which has the following two consecutive lines:
ctrl_end_date=nnnnnnnn
ctrl_process=EXPIRED

where nnnnnnnn is <= 20100902
e.g.
nnnnnnnn is a date string
20070614 and 20100503 meet the criteria
but 20101102 does not.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending Consecutive lines

Hi, I have a file containing a single field on every row. What I need is to append one on to the end of another, e.g. The input file looks like this: nnnnn mmmmmm nnnnn mmmmmm I need it to look like this: nnnnn mmmmmm nnnnn mmmmmm Any ideas would be much appreciated,... (8 Replies)
Discussion started by: pondlife
8 Replies

2. Shell Programming and Scripting

How to delete first 5 lines and last five lines in all text files

Hi I want to delete first five and last five lines in text files without opening the file and also i want to keep the same file name for all the files. Thanks in advance!!! Ragav (10 Replies)
Discussion started by: ragavendran31
10 Replies

3. UNIX Desktop Questions & Answers

How to concatenate consecutive lines

I have a few lines like -- feature 1, subfeat 0, type 3, subtype 1, value 0, -- feature 1, subfeat 0, type 1, subtype 1, value 0, I would like to concatenate the... (1 Reply)
Discussion started by: shivi707
1 Replies

4. UNIX for Dummies Questions & Answers

want to merge two consecutive lines.

Hi All, I want to merge two consecutive lines. Currently the output is :--> crmplp1 cmis461 No Online cmis462 No Offline crmplp2 cmis462 No Online cmis463 No ... (6 Replies)
Discussion started by: pank29
6 Replies

5. Shell Programming and Scripting

Merge two non-consecutive lines

Hello - First post here. I need help combining two lines that are non-consecutive in a file. Using sed, awk or perl preferably. So the file looks as follows. Please note, the "Line#:" is there only for reference. The lines can only be distinguished by whether they have "start" or "done" in... (2 Replies)
Discussion started by: munkee
2 Replies

6. Shell Programming and Scripting

Grep couple of consecutive lines if each lines contains certain string

Hello, I want to extract from a file like : 20120530025502914 | REQUEST | whatever 20120530025502968 | RESPONSE | whatever 20120530025502985 | RESPONSE | whatever 20120530025502996 | REQUEST | whatever 20120530025503013 | REQUEST | whatever 20120530025503045 | RESPONSE | whatever I want... (14 Replies)
Discussion started by: black_fender
14 Replies

7. Shell Programming and Scripting

Read n lines from a text files getting n from within the text file

I dont even have a sample script cause I dont know where to start from. My data lookes like this > sat#16 #data: 15 site:UNZA baseline: 205.9151 0.008 -165.2465 35.8109 40.6685 21.9148 121.1446 26.4629 -18.4976 33.8722 0.017 -165.2243 48.2201 40.6908 ... (8 Replies)
Discussion started by: malandisa
8 Replies

8. UNIX for Dummies Questions & Answers

Finding the same pattern in three consecutive lines in several files in a directory

I know how to search for a pattern/regular expression in many files that I have in a directory. For example, by doing this: grep -Ril "News/U.S." . I can find which files contain the pattern "News/U.S." in a directory. I am unable to accomplish about how to extend this code so that it can... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

9. Shell Programming and Scripting

Grep three consecutive lines if each lines contains certain string

say we have : 2914 | REQUEST | whatever 2914 | RESPONSE | whatever 2914 | SUCCESS | whatever 2985 | RESPONSE | whatever 2986 | REQUEST | whatever 2990 | REQUEST | whatever 2985 | RESPONSE | whatever 2996 | REQUEST | whatever 2010 | SUCCESS | whatever 2013 | REQUEST | whatever 2013 |... (7 Replies)
Discussion started by: Saumitra Pandey
7 Replies

10. Shell Programming and Scripting

Delete all CONSECUTIVE text lines from file shell scripting

Hi I have a text file like below. THe content of the text will vary. Entire text file have four consecutive lines followed with blank line. I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all... (5 Replies)
Discussion started by: RJSKR28
5 Replies
CALLOUT(9)						   BSD Kernel Developer's Manual						CALLOUT(9)

NAME
callout_init, callout_destroy, callout_halt, callout_reset, callout_schedule, callout_setfunc, callout_stop, callout_pending, callout_expired, callout_invoking, callout_ack -- execute a function after a specified length of time SYNOPSIS
#include <sys/callout.h> void callout_init(callout_t *c, u_int flags); void callout_destroy(callout_t *c); void callout_reset(callout_t *c, int ticks, void (*func)(void *), void *arg); void callout_schedule(callout_t *c, int ticks); void callout_setfunc(callout_t *c, void (*func)(void *), void *arg); bool callout_stop(callout_t *c); bool callout_halt(callout_t *c, kmutex_t *interlock); bool callout_pending(callout_t *c); bool callout_expired(callout_t *c); bool callout_active(callout_t *c); bool callout_invoking(callout_t *c); bool callout_ack(callout_t *c); DESCRIPTION
The callout facility provides a mechanism to execute a function at a given time. The timer is based on the hardclock timer which ticks hz times per second. The function is called at softclock interrupt level. Clients of the callout facility are responsible for providing pre-allocated callout structures, or ``handles''. The callout facility replaces the historic UNIX functions timeout() and untimeout(). FUNCTIONS
The callout_init() function initializes the callout handle c for use. No operations can be performed on the callout before it is initial- ized. If the flags argument is CALLOUT_MPSAFE, the handler will be called without getting the global kernel lock. In this case it should only use functions that are multiprocessor safe. callout_destroy() destroys the callout, preventing further use. It is provided as a diagnostic facility intended to catch bugs. To ensure future compatibility, callout_destroy() should always be called when the callout is no longer required (for instance, when a device is being detached). The callout_reset() function resets and starts the timer associated with the callout handle c. When the timer expires after ticks/hz sec- onds, the function specified by func will be called with the argument arg. If the timer associated with the callout handle is already run- ning, the callout will simply be rescheduled to execute at the newly specified time. Once the timer is started, the callout handle is marked as PENDING. Once the timer expires, the handle is marked as EXPIRED and INVOKING, and the PENDING status is cleared. The callout_setfunc() function sets the function and argument of the callout handle c to func and arg respectively. The callout handle must already be initialized. If a callout will always be used with the same function and argument, then callout_setfunc() used in conjunction with callout_schedule() is slightly more efficient than using callout_reset(). The callout_stop() function requests that the timer associated with the callout handle c be stopped. The PENDING and EXPIRED status for the callout handle is cleared. It is safe to call callout_stop() on a callout handle that is not pending, so long as it is initialized. callout_stop() will return a non-zero value if the callout was EXPIRED. Note that callout_stop() can return while the callout is running on a different CPU or at a different interrupt priority level on the current CPU. It can only be said to prevent the callout from firing in the future, unless explicitly re-scheduled. To stop a callout and wait for completion, use callout_halt(). callout_halt() acts much like callout_stop(), but waits for the callout to complete if it is currently in-flight. callout_halt() may not be called from a hard interrupt handler as it will sleep if the callout is currently executing. If the callout can take locks (such as mutexes or RW locks), the caller of callout_halt() must not hold any of those locks, otherwise the two could deadlock. To facilitate this, callout_halt() can optionally release a single mutex specified by the interlock parameter. If interlock is not NULL and the calling thread must wait for the callout to complete, interlock will be released before waiting and re-acquired before returning. If no wait is required, interlock will not be released. However, to avoid race conditions the caller should always assume that interlock has been released and reac- quired, and act accordingly. The callout_pending() function tests the PENDING status of the callout handle c. A PENDING callout is one that has been started and whose function has not yet been called. Note that it is possible for a callout's timer to have expired without its function being called if inter- rupt level has not dropped low enough to let softclock interrupts through. Note that it is only safe to test PENDING status when at soft- clock interrupt level or higher. The callout_expired() function tests to see if the callout's timer has expired and its function called. The callout_active() function returns true if a timer has been started but not explicitly stopped, even if it has already fired. callout_active(foo) is logically the same as callout_pending(foo) || callout_expired(foo); it is implemented as a separate function for com- patibility with FreeBSD and for the special case of TCP_TIMER_ISARMED(). Its use is not recommended. The callout_invoking() function tests the INVOKING status of the callout handle c. This flag is set just before a callout's function is being called. Since the priority level is lowered prior to invocation of the callout function, other pending higher-priority code may run before the callout function is allowed to run. This may create a race condition if this higher-priority code deallocates storage containing one or more callout structures whose callout functions are about to be run. In such cases, one technique to prevent references to deallo- cated storage would be to test whether any callout functions are in the INVOKING state using callout_invoking(), and if so, to mark the data structure and defer storage deallocation until the callout function is allowed to run. For this handshake protocol to work, the callout function will have to use the callout_ack() function to clear this flag. The callout_ack() function clears the INVOKING state in the callout handle c. This is used in situations where it is necessary to protect against the race condition described under callout_invoking(). CONCURRENCY
The callout facility performs locking internally in order to guarantee the atomicity of individual operations performed on callouts. It does not provide life cycle management of user-provided callout data structures, nor does it ensure that groups of operations (multiple function calls) are performed atomically. These aspects of callout management are the responsibility of the user of the callout facility. Scheduled callouts may be active concurrently in a context different to the user of the callout facility: on another CPU, or at a different interrupt priority level or thread on the current CPU. The callout facility provides only one guarantee in this regard: any given callout will never have multiple concurrent invocations. SEE ALSO
condvar(9), hz(9), softint(9), workqueue(9) HISTORY
The callout facility was implemented by Artur Grabowski and Thomas Nordin, based on the work of G. Varghese and A. Lauck, described in the paper Hashed and Hierarchical Timing Wheels: Data Structures for the Efficient Implementation of a Timer Facility in the Proceedings of the 11th ACM Annual Symposium on Operating System Principles, Austin, Texas, November 1987. It was adapted to the NetBSD kernel by Jason R. Thorpe. BSD
August 3, 2009 BSD
All times are GMT -4. The time now is 12:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy