first instance to end of log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting first instance to end of log file
# 1  
Old 07-15-2004
first instance to end of log file

All,

I looking for developing a script which would find the first instance of a date in a log file:

2004/07/15 19:16:09

Here are the next couple lines after the dat time stamp:

backup completed
daemon started.

And I want to put the rest of the lines after the first instance in this log file in a new log file. I do not know how many other line are after the first instance. I just want to find the first instance and pull out the rest of the lines until I reach the end of file into another file. Is there any UNIX commands to perform this operation?

Thanks

Last edited by bubba112557; 07-15-2004 at 09:05 PM..
# 2  
Old 07-16-2004
So you just want the 2004/07/15 19:16:09
in the file and the remainning lines
backup completed
daemon started
in other file

#line will contain the line numbers which are of date format
line=`grep -n "[0-9][0-9][0-9][0-9]\/[0-9][0-9]\/[0-9][0-9]" <inputfilename>|cut -d ":" -f1`
#to get the first occurence of pattern's line no
fline=`echo $line |tr -s "\n" " "|cut -d " " -f1`
# Total number of lines
total=`cat j|wc -l`
#The number of lines to fetch after the first occurence till the end of file
linestofetch=`expr $total - $fline`

tail -n $linestofetch j >outfilename
# 3  
Old 07-16-2004
Could just use awk..

awk '$1=="2004/07/15",0' logfile
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep a log file starting from a specific time to the end of file

I have a log file which have a date and time at the start of every line. I need to search the log file starting from a specific time to the end of file. For example: Starting point: July 29 2018 21:00:00 End point : end of file My concern is what if the pattern of `July 29 2018 21:00:00`... (3 Replies)
Discussion started by: erin00
3 Replies

2. Shell Programming and Scripting

How to keep just one instance in input file?

Hello, I have the following dataset 1 1 2 2 2 3 3 4 I want to keep just one instance of each number seen: 1 2 3 4 (3 Replies)
Discussion started by: Rabu
3 Replies

3. UNIX for Dummies Questions & Answers

Looking for first instance of an error in explorer log

Hi How to see the first instance of an error in explorer log ? In this case I want to know the first time error "SCSI transport failed" was populated in messages Thanks Amani (2 Replies)
Discussion started by: amani
2 Replies

4. Shell Programming and Scripting

How to extract start/end times from log file to CSV file?

Hi, I have a log file (log.txt) that which contains lines of date/time. I need to create a script to extract a CSV file (out.csv) that gets all the sequential times (with only 1 minute difference) together by stating the start time and end time of this period. Sample log file (log.txt) ... (7 Replies)
Discussion started by: Mr.Zizo
7 Replies

5. Shell Programming and Scripting

How to write a new entry at the beginning of a log file instead of at the end?

Hi Ladies and Gents, Explanation of my question with an example: Let's consider the script: backup_every_hour.sh #!/bin/bash rsync -auv $dir $backup_dir >> backup_every_hour_script.log Each time this script is called there will be a new entry at the end of the file... (1 Reply)
Discussion started by: freddie50
1 Replies

6. Shell Programming and Scripting

Search for last instance of word in a file

Hi I'm trying to search for the last instance of the word 'cache' in a HTML file that I have downloaded from YouTube. I'm using the following syntax, but an error is thrown when I try it. grep -f "cache" Also I wish to append the above grep command to the below so that the search for cache... (3 Replies)
Discussion started by: colmbell
3 Replies

7. Shell Programming and Scripting

Getting file names which does not end with .log

Hi All, I have a directory in which all log files will be generated. Apart from the log files, there are a few other files also generated. I want the names of all files which does not end with .LOG. consider the dir has the following files I want only ebaf02012009.ERR file. Unix... (4 Replies)
Discussion started by: suresh_kb211
4 Replies

8. Shell Programming and Scripting

Add end of char \n on end of file

Hi, I want to add \n as a EOF at the end of file if it does't exist in a single command. How to do this? when I use command echo "1\n" > a.txt and od -c a.txt 0000000 1 \n \n 0000003 How does it differentiate \n and eof in this case? Regards, Venkat (1 Reply)
Discussion started by: svenkatareddy
1 Replies

9. Shell Programming and Scripting

Search the last instance of a string in a file

I have a big database log file which keepsgrowing daily. OS is HP UX. Here is a small part of it: Tue Jan 27 04:03:22 2009 : add session begin for mfgeb on /dev/pts/th. : Converting relative path to absolute path. : add session end. Tue Jan 27 04:03:29... (6 Replies)
Discussion started by: dinesh1178
6 Replies

10. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies
Login or Register to Ask a Question