Sponsored Content
Top Forums Shell Programming and Scripting if match found go to a particular line in perl Post 302180579 by era on Monday 31st of March 2008 02:28:22 PM
Old 03-31-2008
I think user_prady means the information needs to be printed already at the point when you see the Main Start although it occurs later in the file. So you need to either move things around in the file (the ugly multi-line regex substitution solution) or keep the stuff between Main Start and Main End in memory, and then print the number first, and then all the lines you have been keeping in memory. However, I'm afraid I don't know how to explain how to do this in more detail without repeating myself. In pseudo-code, something like

Code:
if main_start seen then
  do whatever you do but don't print yet
  instead, push @memory, whatever you would have printed
if main_end then
  print the last line from @memory (pop @memory)
  then print all the other stuff from @memory

In real-world code, you have to move things around a little (figure out if you are coming out of "main start seen" as basically the first thing), but this is only pseudo-code, mind.

I'm reluctant to write code before we get confirmation that this is the actual requirement, though.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Match a line with multiple search patterns

Hi I'm not very good with the serach patterns and I'd need a sample how to find a line that has multiple patterns. Say I want to find a line that has "abd", "123" and "QWERTY" and there can be any characters or numbers between the serach patterns, I have a file that has thousands of lines and... (10 Replies)
Discussion started by: Juha
10 Replies

2. Shell Programming and Scripting

help with script to send email and if subject line match is found

Help with script that will check log, then find a match is found, add that as the subject line. 1. The script will always run as a deamon.. and scan the event.log file 2. when a new 101 line is added to the event.log file, have the script check position 5,6 and 7 which is the job name, which... (2 Replies)
Discussion started by: axdelg
2 Replies

3. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

4. UNIX for Dummies Questions & Answers

Display n lines after match found and other line

I have a file like this DoctorName Address1 Address2 DOB InsuredName Address1 Address2 DOB PatientName Address1 Address2 DOB ClaimNo1 DoctorName Address1 Address2 DOB InsuredName (2 Replies)
Discussion started by: nsuresh316
2 Replies

5. Shell Programming and Scripting

Displaying text till pattern match found in a line

Hi All, From the below line if we want to display all the text till found pattern dot/. I was trying with the below code but couldn't able to print text before the pattern. it display texts which is found after pattern. awk '/assed/{print;getline;print}' file_name | sed 's/^*. *//' input... (4 Replies)
Discussion started by: Optimus81
4 Replies

6. Shell Programming and Scripting

How to print the entire line if the mentioned match is found?

Hello Everyone, I have a file with 5 fields in each line just like mentioned below. Also the 4th field is time elapsed(hh:mm:ss) since the process is running xyz abc status 23:00:00 idle abc def status 24:00:00 idle def gji status 27:00:02 idle fgh gty status 00:00:00 idle Here I... (8 Replies)
Discussion started by: rahul2662
8 Replies

7. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

8. Shell Programming and Scripting

Perl removing line match with pattern in column

Hi, I have log like this: ... (1 Reply)
Discussion started by: justbow
1 Replies

9. Shell Programming and Scripting

Add comment on last line if found match

Hi All, totally new on it , normally use it for just 1 line. i'm looking for help. i'm have 2 file. file 1 : -------------------------------------------------- c12 c1 c3 -------------------------------------------------- file 2: other content ... (10 Replies)
Discussion started by: kttan
10 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies
XtRealloc()															       XtRealloc()

Name
  XtRealloc - change the size of an allocated block of storage.

Synopsis
  char *XtRealloc(ptr, num);
	 char *ptr;
	 Cardinal num;

Inputs
  ptr	    Specifies a pointer to memory allocated with XtMalloc(), XtCalloc(), or XtRealloc(), or NULL.

  num	    Specifies the new number of bytes of memory desired in the block.

Returns
  A pointer to allocated memory.

Description
  XtRealloc() changes the size of the block of allocated memory pointed to by ptr to be at least num bytes large.  In order to make this size
  change, it may have to allocate a new block of memory and copy the contents of the old block (or as much as will fit) into the  new  block.
  If  it  allocates a new block of memory, it frees the old block.  In either case, it returns a pointer to a block of memory which is of the
  requested size.  If there is insufficient memory to allocate the new block, XtRealloc() terminates by calling XtErrorMsg().

  If ptr is NULL, XtRealloc() simply calls XtMalloc() to allocate a block of memory of the requested size.

Usage
  Note that XtRealloc() may move the contents of your allocated memory to a new location; the return value may or may not be the same as ptr.
  Not  all  memory can be safely reallocated.  If there are multiple pointers to a block of memory scattered through out an application (such
  as pointers to a widget record), then reallocating that memory is not safe, because all pointers to it cannot  be  updated.	Other  memory
  (such  as  the array of children maintained privately by the Composite widget class) can be safely updated because there should be only one
  pointer to it in the application (in this case the pointer is the composite.children field of the widget).  These cautions are no different
  than those required with the standard realloc() function.

  In most cases, you will have to cast the return value of XtRealloc() to an appropriate pointer type.

  Note that because XtRealloc() behaves like XtMalloc() when passed a NULL pointer, (something that realloc() does not do), you don't have to
  write special case code to allocate the first chunk of memory with XtMalloc() and subsequent chunks with XtRealloc(); you  can  simply  use
  XtRealloc() everywhere.

  Memory  allocated with XtRealloc() must be deallocated with XtFree().  The function XtRealloc() is implemented by the Toolkit independently
  of the particular environment, so programs ported to a system not supporting malloc will still work.

See Also
  XtCalloc(1), XtFree(1), XtMalloc(1), XtNew(1), XtNewString(1).

Xt - Memory Allocation														       XtRealloc()
All times are GMT -4. The time now is 02:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy