Sponsored Content
Top Forums Shell Programming and Scripting Grepping a timestamp range and assigning it to a constant Post 302994555 by Corona688 on Friday 24th of March 2017 11:33:54 AM
Old 03-24-2017
Why not just use awk to do all of that in the first place? Unlike sed, awk actually has a proper 'greater than' operator. Even better, it has variables and math, so it can actually calculate which range its in.

Code:
$ cat inputfile

junk,00:00:00,00:00:00
junk,00:30:00,00:00:00
junk,01:00:00,00:00:00
junk,01:30:00,00:00:00
junk,02:00:00,00:00:00
junk,02:30:00,00:00:00
junk,03:00:00,00:00:00
junk,03:30:00,00:00:00
junk,04:00:00,00:00:00
junk,04:30:00,00:00:00
junk,05:00:00,00:00:00
junk,05:30:00,00:00:00
junk,06:00:00,00:00:00
junk,06:30:00,00:00:00
junk,07:00:00,00:00:00
junk,07:30:00,00:00:00
junk,08:00:00,00:00:00
junk,08:30:00,00:00:00
junk,09:00:00,00:00:00
junk,09:30:00,00:00:00
junk,10:00:00,00:00:00
junk,10:30:00,00:00:00
junk,11:00:00,00:00:00
junk,11:30:00,00:00:00
junk,12:00:00,00:00:00
junk,12:30:00,00:00:00
junk,13:00:00,00:00:00
junk,13:30:00,00:00:00
junk,14:00:00,00:00:00
junk,14:30:00,00:00:00
junk,15:00:00,00:00:00
junk,15:30:00,00:00:00
junk,16:00:00,00:00:00
junk,16:30:00,00:00:00
junk,17:00:00,00:00:00
junk,17:30:00,00:00:00
junk,18:00:00,00:00:00
junk,18:30:00,00:00:00
junk,19:00:00,00:00:00
junk,19:30:00,00:00:00
junk,20:00:00,00:00:00
junk,20:30:00,00:00:00
junk,21:00:00,00:00:00
junk,21:30:00,00:00:00
junk,22:00:00,00:00:00
junk,22:30:00,00:00:00
junk,23:00:00,00:00:00
junk,23:30:00,00:00:00

$ awk -F"," -v OFS="," '{
        split($2, A, ":");
        sub(/^0/, "", A[1]); # Remove leading zero
        A[1] += 0; # Convert from string into number
        $2=sprintf("CUT %d", (A[1] / 3) + 1); # Calculate and truncate to integer
        NF=2 # Cut off third field
} 1' inputfile

junk,CUT 1
junk,CUT 1
junk,CUT 1
junk,CUT 1
junk,CUT 1
junk,CUT 1
junk,CUT 2
junk,CUT 2
junk,CUT 2
junk,CUT 2
junk,CUT 2
junk,CUT 2
junk,CUT 3
junk,CUT 3
junk,CUT 3
junk,CUT 3
junk,CUT 3
junk,CUT 3
junk,CUT 4
junk,CUT 4
junk,CUT 4
junk,CUT 4
junk,CUT 4
junk,CUT 4
junk,CUT 5
junk,CUT 5
junk,CUT 5
junk,CUT 5
junk,CUT 5
junk,CUT 5
junk,CUT 6
junk,CUT 6
junk,CUT 6
junk,CUT 6
junk,CUT 6
junk,CUT 6
junk,CUT 7
junk,CUT 7
junk,CUT 7
junk,CUT 7
junk,CUT 7
junk,CUT 7
junk,CUT 8
junk,CUT 8
junk,CUT 8
junk,CUT 8
junk,CUT 8
junk,CUT 8

$

 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

2. Programming

grepping a range of values

I need to return all records in a file starting with a row that says TABLE: <tabl name> lists of hexadecimal records TABLE: <some table> TABLe is a key word in the file. I know the name of the table I want to start with. I do not know the name of the table that I will end with. I just... (4 Replies)
Discussion started by: guessingo
4 Replies

3. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

4. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

5. IP Networking

IP Range Assigning

Hi All, I'm a bit confused about assigning IP address from IP Ranges. I am using this scenario below to understand. Scenario Adatum.com an international IT solutions company, is launching 12 new branches in a new country where they currently have no existing branches. The sWin CIO has asked... (3 Replies)
Discussion started by: TryllZ
3 Replies

6. Homework & Coursework Questions

IP Range Assigning

THIS IS A SAMPLE PRACTICAL EXAM QUESTION, COMPLETE FILE HAS BEEN ATTACHED AS WELL. Hi All, I'm a bit confused about assigning IP address from IP Ranges. I am using this scenario below to understand. Scenario Adatum.com an international IT solutions company, is launching 12 new branches in a... (10 Replies)
Discussion started by: TryllZ
10 Replies

7. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies
ACTIVE(5)						    InterNetNews Documentation							 ACTIVE(5)

NAME
active - List of newsgroups carried by the server DESCRIPTION
The file pathdb/active lists the newsgroups carried by INN. This file is generally maintained using ctlinnd(8) to create and remove groups, or by letting controlchan(8) do so on the basis of received control messages; this file is then updated and a backup stored in pathdb/active.old. Note that the newsgroups(5) file normally contains the descriptions of the newsgroups carried by the news server. The active file should not be edited directly without throttling innd, and must be reloaded using ctlinnd before innd is unthrottled. Editing it directly even with those precautions may make it inconsistent with the overview database and won't update active.times, so ctlinnd should be used to make modifications whenever possible. Each newsgroup should be listed only once. Each line specifies one group. The order of groups does not matter. Within each newsgroup, received articles for that group are assigned monotonically increasing numbers as unique names. If an article is posted to newsgroups not mentioned in this file, those newsgroups are ignored. If none of the newsgroups listed in the Newsgroups: header of an article are present in this file, the article is either rejected (if wanttrash is false in inn.conf), or is filed into the newsgroup "junk" and, when "Aj" is not set in the newsfeeds feed pattern, only propagated to sites that receive the "junk" newsgroup (if wanttrash is true). Each line of this file consists of four fields separated by a space: <name> <high> <low> <status> The first field is the name of the newsgroup. The newsgroup "junk" is special, as mentioned above. The newsgroup "control" and any newsgroups beginning with "control." are also special; control messages are filed into a control.* newsgroup named after the type of control message if that group exists, and otherwise are filed into the newsgroup "control" (without regard to what newsgroups are listed in the Newsgroups: header). If mergetogroups is set to true in inn.conf, newsgroups that begin with "to." are also treated specially; see innd(8). The second field is the highest article number that has been used in that newsgroup. The third field is the lowest article number in the group; this number is not guaranteed to be accurate, and should only be taken to be a hint. It is normally updated nightly as part of the expire process; see news.daily(8) and look for "lowmark" or "renumber" for more details. Note that because of article cancellations, there may be gaps in the numbering sequence. If the lowest article number is greater than the highest article number, then there are no articles in the newsgroup. In order to make it possible to update an entry in-place without rewriting the entire file, the second and third fields are padded out with leading zeros to make them a fixed width. The fourth field contains one of the following status: y Local postings and articles from peers are allowed. m The group is moderated and all postings must be approved. n No local postings are allowed, only articles from peers. j Articles from peers are filed in the junk group instead. x No local postings, and articles from peers are ignored. =foo.bar Articles are filed in the group foo.bar instead. If a newsgroup has the "j" status, no articles will be filed in that newsgroup. Local postings are not accepted; if an article for that newsgroup is received from a remote site, and if it is not crossposted to some other valid group, it will be filed into the "junk" newsgroup instead. This is different than simply not listing the group, since the article will still be accepted and can be propagated to other sites, and the "junk" group can be made available to readers if wished. If the <status> field begins with an equal sign, the newsgroup is an alias. Articles cannot be posted to that newsgroup, but they can be received from other sites. Any articles received from peers for that newsgroup are treated as if they were actually posted to the group named after the equal sign. Note that the Newsgroups: header of the articles is not modified. (Alias groups are typically used during a transition and are typically created manually with ctlinnd(8).) An alias should not point to another alias. Note that readers.conf can be configured so that local posts to newsgroups with status "j", "n" or "x" are accepted. MINIMAL ACTIVE FILE
For innd to be able to start, the three groups "control", "control.cancel" and "junk" need to be in the active file. Besides, if mergetogroups is set to true in inn.conf, the newsgroup "to" also needs to exist. The minimal active file shipped with INN is: control 0000000000 0000000001 n control.cancel 0000000000 0000000001 n control.checkgroups 0000000000 0000000001 n control.newgroup 0000000000 0000000001 n control.rmgroup 0000000000 0000000001 n junk 0000000000 0000000001 n (Note that the second and the third field may differ if the news server has already been in use.) There are more control.* pseudogroups here than needed by innd to start; the corresponding control messages will be filed into them. The "n" status is so that users cannot post directly to these groups (control messages should only be posted to the groups that they affect). If you do not want these groups to be visible to clients, do not delete them but simply hide them in readers.conf(5). To create additional groups after the server is running, you can use "ctlinnd newgroup". You can also synchronize your newsgroup list to that of another server by using actsync(8) or get the active file of another NNTP server with getlist(1). And do not forget to update your newsgroups file, which can be automatically done thanks to docheckgroups called with the -u flag. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. Converted to POD by Russ Allbery <rra@stanford.edu>. $Id: active.pod 9031 2010-03-23 18:31:55Z iulius $ SEE ALSO
active.times(5), actsync(8), controlchan(8), ctlinnd(8), docheckgroups(8), getlist(1), inn.conf(5), innd(8), mod-active(8), news.daily(8), newsgroups(5), readers.conf(5). INN 2.5.2 2010-03-23 ACTIVE(5)
All times are GMT -4. The time now is 02:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy