Sponsored Content
Top Forums Shell Programming and Scripting Search a String between start and end of a block in a file Post 303013537 by MadeInGermany on Friday 23rd of February 2018 02:13:44 AM
Old 02-23-2018
I think the flag should control a bit more. For example a further abc within a block should be ignored. Dito a further def outside the block.
The logical OR is ||
Code:
awk '{
  if (flag==0) {
    if (/^abc$/) {
      flag=1; block=$0
    }
  } else {
    block=(block RS $0)
    if (/^def$/) {
      flag=0; if (block ~ "123" || block ~ "456") print block
    }
  }
}' values.txt


Last edited by MadeInGermany; 02-23-2018 at 05:09 PM.. Reason: RS not FS
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

String as both start and end anchors in awk

Not sure if the title of this thread makes sense, but hopefully my explanation will. I'm using awk to print some stats from an apache accesslog. I would like to specify the regexp condition where only the two root pages of "index.html" and "/" are counted in my results. What I can't figure out... (3 Replies)
Discussion started by: picassolsus
3 Replies

2. Shell Programming and Scripting

Appending string, variable to file at the start and string at end

Hi , I have below file with 13 columns. I need 2-13 columns seperated by comma and I want to append each row with a string "INSERT INTO xxx" in the begining as 1st column and then a variable "$node" and then $2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13 and at the end another string " ; COMMIT;" ... (4 Replies)
Discussion started by: Vaddadi
4 Replies

3. Shell Programming and Scripting

read a string from its end to its start and stop when you find a specific character

How can I do this? Actually I have a file which contains a path e.g. /home/john/Music/hello.mp3 and I want to take only the filename (hello.mp3) So, I need to read the file from its end to its start till the character "/" Is this possible? Thanks, I am sure you'll not disappoint me here! Oh,... (9 Replies)
Discussion started by: hakermania
9 Replies

4. Shell Programming and Scripting

how to specify start and stop of a search string

I am trying to extract a string from a line of text. Currently I am using grep -o 'startofstring(.........' The string is not always the same size. The string I'm trying to extract starts with 'test(' ends with ')'. ex "blah,blah,blah,test(stringoftext),blah blah" How do I... (4 Replies)
Discussion started by: jeepguy
4 Replies

5. Shell Programming and Scripting

Remove lines between the start string and end string including start and end string Python

Hi, I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
Discussion started by: Dabheeruz
1 Replies

6. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

7. Shell Programming and Scripting

How can I search with start and end criteria?

Hello I'm using cygwin and wouldlike extract information from an xml file according specific values, but don't know how. Let's say in a file content looks like this: <tab> SURNAME=Mustermann NAME=Max CUSTOMER SINCE= 18.01.2000 ADDRESS=Birmingham ... (2 Replies)
Discussion started by: witchblade
2 Replies

8. UNIX for Beginners Questions & Answers

Search a string inside a pattern matched block of a file

How to grep for searching a string within a begin and end pattern of a file. Sent from my Redmi 3S using Tapatalk (8 Replies)
Discussion started by: Baishali
8 Replies

9. Shell Programming and Scripting

Printing string from last field of the nth line of file to start (or end) of each line (awk I think)

My file (the output of an experiment) starts off looking like this, _____________________________________________________________ Subjects incorporated to date: 001 Data file started on machine PKSHS260-05CP ********************************************************************** Subject 1,... (9 Replies)
Discussion started by: samonl
9 Replies

10. UNIX for Beginners Questions & Answers

How do delete certain lines alone which are matching with start and end string values in file?

Hi, In my previous post ( How to print lines from a files with specific start and end patterns and pick only the last lines? ), i have got a help to get the last select statement from a file, now i need to remove/exclude the output from main file: Input File format: SELECT ABCD, DEFGH,... (2 Replies)
Discussion started by: nani2019
2 Replies
DATEPERIOD.__CONSTRUCT(3)						 1						 DATEPERIOD.__CONSTRUCT(3)

DatePeriod::__construct - Creates a new DatePeriod object

SYNOPSIS
public DatePeriod::__construct (DateTimeInterface $start, DateInterval $interval, int $recurrences, [int $options]) DESCRIPTION
DatePeriod::__construct (DateTimeInterface $start, DateInterval $interval, DateTimeInterface $end, [int $options]) DatePeriod::__con- struct (string $isostr, [int $options]) Creates a new DatePeriod object. PARAMETERS
o $start - The start date of the period. o $interval - The interval between recurrences within the period. o $recurrences - The number of recurrences. o $end - The end date of the period. o $isostr - An ISO 8601 repeating interval specification. o $options - Can be set to DatePeriod::EXCLUDE_START_DATE to exclude the start date from the set of recurring dates within the period. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.5.8 | | | | | | | $end type changed to DateTimeImmutable. Previ- | | | ously, DateTime. | | | | | 5.5.0 | | | | | | | $start type changed to DateTimeImmutable. Previ- | | | ously, DateTime. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 DatePeriod example <?php $start = new DateTime('2012-07-01'); $interval = new DateInterval('P7D'); $end = new DateTime('2012-07-31'); $recurrences = 4; $iso = 'R4/2012-07-01T00:00:00Z/P7D'; // All of these periods are equivalent. $period = new DatePeriod($start, $interval, $recurrences); $period = new DatePeriod($start, $interval, $end); $period = new DatePeriod($iso); // By iterating over the DatePeriod object, all of the // recurring dates within that period are printed. foreach ($period as $date) { echo $date->format('Y-m-d')." "; } ?> The above example will output: 2012-07-01 2012-07-08 2012-07-15 2012-07-22 2012-07-29 Example #2 DatePeriod example with DatePeriod::EXCLUDE_START_DATE <?php $start = new DateTime('2012-07-01'); $interval = new DateInterval('P7D'); $end = new DateTime('2012-07-31'); $period = new DatePeriod($start, $interval, $end, DatePeriod::EXCLUDE_START_DATE); // By iterating over the DatePeriod object, all of the // recurring dates within that period are printed. // Note that, in this case, 2012-07-01 is not printed. foreach ($period as $date) { echo $date->format('Y-m-d')." "; } ?> The above example will output: 2012-07-08 2012-07-15 2012-07-22 2012-07-29 PHP Documentation Group DATEPERIOD.__CONSTRUCT(3)
All times are GMT -4. The time now is 11:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy