I need to isolate a date in a large log file

Thread Tools Search this Thread
# 1  
I need to isolate a date in a large log file

I wrote head -n1 example.log I grab the first line of the log, but I need to isolate just the date, which is 08/May/2012:09:52:52. I also need to find the reverse of this, which would be tail...


Thanks in advance
# 2  
Is the date always the third field, and inside brackets?

# 3  
I guess that it works
head -n1 example.log| awk -F[ '{print $2}'|awk -F] '{print $1}'

# 4  
Assuming date is always the third field inside square brackets.

From header:
awk 'NR==1{gsub(/\[|\]/,X); print $3; }' example.log

From trailer:
awk 'END{gsub(/\[|\]/,X); print $3; }' example.log

# 5  
Originally Posted by joeyg
Is the date always the third field, and inside brackets?

Yes, it is. I also need to grab the last entry in this same log file as well, however, my instructor wants us to utilize cut instead of awk.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #300
Difficulty: Easy
The basis for the first versions of the Slackware Linux distributions was Debian Linux.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Strip the first record off a file and isolate fields off of it

I have a 2 part question on how to this in unix scripting using kshell or c shell. I have a file described below: 1st record has 2 fields on it every other record has 22 fields on it. Example ABC, email address Detail 1 Detail 2 Detail 3 . . . 1st question is... (4 Replies)
Discussion started by: jclanc8
4 Replies

2. Shell Programming and Scripting

Splitting a large file as per date

Hi, I need a suggestion for an issue in UNIX file. I have a log file in my system where data is appending everyday and as a consequence the file is increasing heavily everyday. Now I need a logic to split this file daily basis and remove the files more than 15 days. Request you to... (3 Replies)
Discussion started by: bhaski2012
3 Replies

3. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

4. Shell Programming and Scripting

Store and isolate bad pages from a file to new file

I have a file like below . The good pages must have 3 conditions : The pages that containing page total only must have 50 lines. The pages that containing customer total only must have 53 lines. The last page of Customer Total should be the last page. How can I accomplish separating good... (1 Reply)
Discussion started by: ehabaziz2001
1 Replies

5. Red Hat

Help for capturing a URL from a line from large log file

Can someone please help me how do I find a URL from lines of log file and write all the output to a new file? For e.g - Log file has similar entries, - - "GET /abc/login?service= HTTP/1.1" 401 3218 - - "GET... (2 Replies)
Discussion started by: rockf1bull
2 Replies

6. Shell Programming and Scripting

awk: isolate a part of a file name

hi there, i have a file named 'x20080613_x20100106.pwr1.gc', i want to isolate the part 'x20080613_x20100106' but by using the following line i isolate the part '.pwr1.gc': `awk '$0=substr($0, length($0)-7)' $temp` how can i reverse that? thank you! (3 Replies)
Discussion started by: friend
3 Replies

7. UNIX for Dummies Questions & Answers

sed to isolate file paths separated by a pattern

Hi, I've been searching for a quick way to do this with sed, but to no avail. I have a file containing a long series of (windows) file paths that are separated by the pattern '@'. I would like to extract each file path so that I can later assign a variable to each path. Here is the file:... (2 Replies)
Discussion started by: nixjennings
2 Replies

8. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

9. Shell Programming and Scripting

Cutting a large log file in to smaller ones

I have a very large (150 megs) IRC log file from 2000-2001 which I want to cut down to individual daily log files. I have a very basic knowledge of the cat, sed and grep commands. The log file is time stamped and each day in the large log file begins with a "Session Start" string like so: ... (11 Replies)
Discussion started by: MrTangent
11 Replies

10. UNIX for Dummies Questions & Answers

Splitting a large log file

Okay, absolute newbie here... I'm on a Mac trying to split an almost 2 Gig log file on a Unix box into manageable chunks for my web-based log analysis tool. What do I need to do, what programs do I need to do it? All and any help appreciated/needed :-) Cheers (8 Replies)
Discussion started by: simmonet
8 Replies

Featured Tech Videos