Grepping a timestamp range and assigning it to a constant


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping a timestamp range and assigning it to a constant
# 15  
Old 03-24-2017
Quote:
Originally Posted by Corona688
Simpler version which doesn't need any arrays, just substitution and math:

Code:
awk -F"[,:]" -v OFS="," '{
        sub(/^0/, "", $2);      # Remove leading zero
        $2=sprintf("CUT %d", ($2/3)+1); # Set column 2 to "CUT N"
        NF=2                    # Set number of columns to 2
        print                   # print
}'

in your code it is printing CUT 6 for a timestamp which is 4 PM, which is actually CUT 1. CUT 1 is between 3pm-5pm, CUT 2 is between 6pm-10pm and CUT 3 is between 00:00 - 3am.
# 16  
Old 03-24-2017
Quote:
Originally Posted by dsid
in your code it is printing CUT 6 for a timestamp which is 4 PM, which is actually CUT 1. CUT 1 is between 3pm-5pm, CUT 2 is between 6pm-10pm and CUT 3 is between 00:00 - 3am.
does it really matter what "cut" corresponds to what time bucket?
you said previously:
Quote:
Originally Posted by dsid
@RudiC @vgersh99 My argument is that instead of numbers(time stamps) I want constant characters in place of the time stamp so that I can sort and count it. Because of the different time stamps I am unable to sort them
wouldn't bucketing the records 3 hours each be sufficient for the above purpose?
# 17  
Old 03-24-2017
once i figure out what CUT that particular time period is from, Im basically assigning similar CUT names to a time period range. Once that is finished, I will club all the incoming files in that CUT and will count the total number of files belonging to that CUT
# 18  
Old 03-24-2017
Try
Code:
sed -r 's/,1[567](:[0-9]{2}){2}/ CUT 1/; s/,(1[89]|2[012])(:[0-9]{2}){2}/ CUT 2/; s/,0[012](:[0-9]{2}){2}/ CUT 3/' file

# 19  
Old 03-24-2017
Quote:
Originally Posted by RudiC
Try
Code:
sed -r 's/,1[567](:[0-9]{2}){2}/ CUT 1/; s/,(1[89]|2[012])(:[0-9]{2}){2}/ CUT 2/; s/,0[012](:[0-9]{2}){2}/ CUT 3/' file

sure. I am travelling now, once I reach home I will get back with an update
# 20  
Old 03-24-2017
Quote:
Originally Posted by dsid
in your code it is printing CUT 6 for a timestamp which is 4 PM, which is actually CUT 1. CUT 1 is between 3pm-5pm, CUT 2 is between 6pm-10pm and CUT 3 is between 00:00 - 3am.
Thank you for clarifying this, we've been asking for a while if that was a typo or not.
# 21  
Old 03-24-2017
@corona688 sorry if you got offended. i didnt mean it that way. i only posed a question cos i had run your code as it is
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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. 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

6. 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

7. 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
Login or Register to Ask a Question