Sponsored Content
Top Forums Shell Programming and Scripting To print lines between 2 timestamps using awk|sed and regex Post 302791025 by sarah-alikhan31 on Sunday 7th of April 2013 04:55:45 PM
Old 04-07-2013
Hammer & Screwdriver To print lines between 2 timestamps using awk|sed and regex

Hi,

I am using the following code to fetch lines that are generated in last 1 hr . Hence, I am using date function to calculate -last 1 hr & the current hr and then somehow use awk (or sed-if someone could guide me better)
with some regex pattern.
Code:
dt_1=`date +%h" "%d", "%Y\ %l -d  "1 hour ago"`  #Apr 05, 2013 1   --- if ran at 02 AM
dt_2=`date +%p -d  "1 hour ago"`  # AM|PM
echo $dt_1
echo $dt_2
dt_3=`date +%h" "%d", "%Y\ %l`
dt_4=`date +%p`
echo $dt_3
echo $dt_4
awk  -v a="{$dt_1}" -v b="{$dt_2}" -v c="{$dt_3}" -v d="{$dt_4}" '$0~/a:[0-9][0-9]:[0-9][0-9] b/{flag=1;next} $0~/c:[0-9][0-9]:[0-9][0-9] d/{flag=0} flag' /some/logfile >> /some/dump_logs.txt

The above code doesnot give any errors and I have also tried without $0~

Let's say I want all the lines starting from
Apr 07, 2013 1:mm:ss AM
to
Apr 07, 2013 2:mm:ss AM

if script gets executed b/w 2:00-2:59 hrs

OR
lines between
Apr 07, 2013 12:mm:ss PM
to
Apr 07, 2013 1:mm:ss PM

if script gets executed b/w 13:00-13:59 hrs

I have been searching for similar posts reported by various users, but I can only see variables being used in awk, without any regex pattern.

Could anyone please guide me here ?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed - print only matching regex

Hi folks, Lets say I have the following text file: name, lastname, 1234, name.lastname@test.com name1, lastname1, name2.lastname2@test.com, 2345 name, 3456, lastname, name3.lastname3@test.com 4567, name, lastname, name4.lastname4@test.com I now need the following output: 1234... (5 Replies)
Discussion started by: domi55
5 Replies

2. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

3. Shell Programming and Scripting

Print lines after regex

Hello, I need to print four lines inmediatly after the regexp, but not the line containing the regexp. The print should show the four lines together in one. Thanks! (13 Replies)
Discussion started by: auratus42
13 Replies

4. Shell Programming and Scripting

How to print the lines between the pattern using awk/grep/sed?

Hi, I need a help to search a pattern and print the multiple lines between them. Input file: Tue May 29 12:30:33 EDT 2012:threadWebContainer : 357:com.travimp.hotelierlinks.abba.service.RequestHandler.requestService(String, ITICSDataSet): hotelCancelReservation request: ... (4 Replies)
Discussion started by: aroragaurav.84
4 Replies

5. Shell Programming and Scripting

Print lines between two strings multiple occurencies (with sed, awk, or grep)

Hello, I can extract lines in a file, between two strings but only one time. If there are multiple occurencies, my command show only one block. Example, monfichier.txt contains : debut_sect texte L1 texte L2 texte L3 texte L4 fin_sect donnees inutiles 1 donnees inutiles 2 ... (8 Replies)
Discussion started by: theclem35
8 Replies

6. Shell Programming and Scripting

Print lines that match regex on xth string

Hello, I need an awk command to print only the lines that match regex on xth field from file. For example if I use this command awk -F"|" ' $22 == "20130117090000.*" 'It wont work, I think, because single quotes wont allow the usage of the metacharacter star * . On the other hand I dont know... (2 Replies)
Discussion started by: black_fender
2 Replies

7. UNIX for Advanced & Expert Users

awk print all fields except matching regex

grep -v will exclude matching lines, but I want something that will print all lines but exclude a matching field. The pattern that I want excluded is '/mnt/svn' If there is a better solution than awk I am happy to hear about it, but I would like to see this done in awk as well. I know I can... (11 Replies)
Discussion started by: glev2005
11 Replies

8. UNIX for Advanced & Expert Users

sed REGEX to print multiple occurrences of a pattern from a line

I have a line that I need to parse through and extract a pattern that occurs multiple times in it. Example line: getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed,... (4 Replies)
Discussion started by: Vidhyaprakash
4 Replies

9. Shell Programming and Scripting

(n)awk: print regex search output lines in one line

Hello. I have been looking high and low for the solution for this. I seems there should be a simple answer, but alas. I have a big xml file, and I need to extract certain information from specific items. The information I need can be found between a specific set of tags. let's call them... (2 Replies)
Discussion started by: Tobias-Reiper
2 Replies

10. UNIX for Beginners Questions & Answers

Sed/awk to delete a regex between range of lines

Hi Guys I am looking for a solution to one problem to remove parentheses in a range of lines. Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj;... (5 Replies)
Discussion started by: kshitij
5 Replies
DATEFMT_FORMAT_OBJECT(3)						 1						  DATEFMT_FORMAT_OBJECT(3)

IntlDateFormatter::formatObject - Formats an object

	Object oriented style

SYNOPSIS
publicstatic string IntlDateFormatter::formatObject (object $object, [mixed $format = NULL], [string $locale = NULL]) DESCRIPTION
Procedural style string datefmt_format_object (object $object, [mixed $format = NULL], [string $locale = NULL]) This function allows formatting an IntlCalendar or DateTime object without first explicitly creating a IntlDateFormatter object. The temporary IntlDateFormatter that will be created will take the timezone from the passed in object. The timezone database bundled with PHP will not be used - ICU's will be used instead. The timezone identifier used in DateTime objects must therefore also exist in ICU's database. PARAMETERS
o $object - An object of type IntlCalendar or DateTime. The timezone information in the object will be used. o $format - How to format the date/time. This can either be an array with two elements (first the date style, then the time style, these being one of the constants IntlDateFormatter::NONE, IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG, IntlDateFormatter::FULL), a long with the value of one of these constants (in which case it will be used both for the time and the date) or a string with the format described in the ICU documentation. If NULL, the default style will be used. o $locale - The locale to use, or NULL to use the default one. RETURN VALUES
A string with result or FALSE on failure. EXAMPLES
Example #1 datefmt_format_object(3) examples <?php /* default timezone is irrelevant; timezone taken from the object */ ini_set('date.timezone', 'UTC'); /* default locale is taken from this ini setting */ ini_set('intl.default_locale', 'fr_FR'); $cal = IntlCalendar::fromDateTime("2013-06-06 17:05:06 Europe/Dublin"); echo "default: ", IntlDateFormatter::formatObject($cal), " "; echo "long $format (full): ", IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), " "; echo "array $format (none, full): ", IntlDateFormatter::formatObject($cal, array( IntlDateFormatter::NONE, IntlDateFormatter::FULL)), " "; echo "string $format (d 'of' MMMM y): ", IntlDateFormatter::formatObject($cal, "d 'of' MMMM y", 'en_US'), " "; echo "with DateTime: ", IntlDateFormatter::formatObject( new DateTime("2013-09-09 09:09:09 Europe/Madrid"), IntlDateFormatter::FULL, 'es_ES'), " "; The above example will output: default: 6 juin 2013 17:05:06 long $format (full): jeudi 6 juin 2013 17:05:06 heure d'ete irlandaise array $format (none, full): 17:05:06 heure d'ete irlandaise string $format (d 'of' MMMM y): 6 of June 2013 with DateTime: lunes, 9 de septiembre de 2013 09:09:09 Hora de verano de Europa central PHP Documentation Group DATEFMT_FORMAT_OBJECT(3)
All times are GMT -4. The time now is 04:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy