Sponsored Content
Top Forums Shell Programming and Scripting Interactive filters for log file (beginner) Post 302528836 by acidoangel on Wednesday 8th of June 2011 05:01:38 AM
Old 06-08-2011
Quote:
Originally Posted by itkamaraj
Code:
awk ' /^11:[34][0-9]:[0-9][0-0]/ {print}' filename

Code:
start_line=`grep -n -m 1 "^11:30:00" filename | awk '{print $1}'`
end_line=`grep -n -m 1 "^11:40:00" filename | awk '{print $1}'`
sed '"$start_line","$end_line"p' filename

Thanks for your solution but it's work only for my example.
For example if I choose time range between 15:40:00 and 23:10:00
this solution doens't work Smilie

Quote:
Originally Posted by Skrynesaver
Or for something more re-usable (DATA section for illustration, you'd have to open the file for reading in a programmed script.
Code:
#!/usr/bin/perl

@divs=qw(hour min sec milis);
@start{@divs} = $ARGV[0]=~/(\d+)/g;
@end{@divs} = $ARGV[1]=~/(\d+)/g;
while(<DATA>){
    chomp;
    @time{@divs} = $_ =~/(\d+):/g;
    if ((after(\%time, \%start)) && (! after(\%time, \%end))){
        print "$_\n";
    }
}
sub after{
    my ($time,$limit)=@_;
    for (@divs){
        if ($time->{$_} < $limit->{$_}){
            return 0;
        }
        elsif ($time->{$_} > $limit->{$_}){
            return 1;
        }
    }
    return 1;
}
__DATA__
10:02:23:124.id_0000.1:"blalba"
10:05:26:124.id_0000.1:"blalba"
10:10:32:124.id_0000.1:"blalba"
11:32:36:124.id_0000.1:"blalba"
11:33:49:124.id_0000.1:"blalba"
11:36:23:124.id_0000.1:"blalba"
12:10:21:124.id_0000.1:"blalba"
12:20:21:124.id_0000.1:"blalba"
12:30:21:124.id_0000.1:"blalba"

Thanks a lot for this very nice solution Smilie
I have a lot of work to undestand in depth your code ^_^


But , anyway to do it with awk ?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

IP Filters

Anyone know where I can find good documentation for IPF on the Internet? Thanks, Chuck (1 Reply)
Discussion started by: 98_1LE
1 Replies

2. UNIX for Dummies Questions & Answers

filters

how to filter one particular row from one text file and copy it in another? (1 Reply)
Discussion started by: rajanandhini
1 Replies

3. UNIX for Dummies Questions & Answers

.bashrc file is an initialization file run by each interactive invocation

I search the web and found the following statements ..... The /etc/profile file is a system wide initialization script which is run at login time for each user, while .profile is the users own login initialization. The .bashrc file is an initialization file run by each interactive invocation... (1 Reply)
Discussion started by: cy163
1 Replies

4. Shell Programming and Scripting

Need help with Interactive rename file.

hey all i was writing a script to 1. Rename a file upon the user's request. If the file exists, prompt the user for confirmation before renaming the file. The screen should prompt the user for a. “Name of file you want to rename.” Use the “\c” escape character. b. ... (36 Replies)
Discussion started by: keyboardkowboy
36 Replies

5. UNIX for Dummies Questions & Answers

(Beginner) Run c++ .exe with input to file

Hi, I've got this requirement for my homework assignment, but I'm not sure how to meet it: In the comamnd line, I need to type $ <exec-file> <input> <output_file_name> Like: test 1+2 out.txt Which should execute test.exe passing in 1+2 and directing output to out.txt. I know how... (1 Reply)
Discussion started by: JustinT
1 Replies

6. Homework & Coursework Questions

Help with Interactive / Non Interactive Shell script

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (1 Reply)
Discussion started by: rits
1 Replies

7. Homework & Coursework Questions

How to write script that behaves both in interactive and non interactive mode

Q. Write a script that behaves both in interactive and non interactive mode. When no arguments are supplied it picks up each C program from the directory and prints first 10 lines. It then prompts for deletion of the file. If user supplies arguments with the script , then it works on those files... (8 Replies)
Discussion started by: rits
8 Replies

8. Shell Programming and Scripting

Need help in filters

Hi, I have input data. 9214919702; B5; 1;20070216; 9231590437; BY; 1;20070215;9;20091022;12;20091022; 9211765888; AZ; 1;20080802;1;20080802;14;20091027; 9231592590; BY; 1;20070215;9;20091026;9;20091026; 9252412219; MM; 1;20070217; 9214917135; MM; 1;20070215; 9214917056; B5; 1;20070215;... (8 Replies)
Discussion started by: suresh3566
8 Replies

9. Shell Programming and Scripting

Creating an excel file with filters using shell script.

Hi All, I am new to shell scripting. I have made a script that can convert an excel file from cvs file. This excel file contains hundreds of records and i would like the reader to be able to filter. Is it possible to create an excel file with filters? or that functionality has not been... (3 Replies)
Discussion started by: Marvin159875321
3 Replies

10. Shell Programming and Scripting

Beginner need help how file moving script could look like

Hi there, I am an absolut beginner in scripting. I am using Ubuntu Linux 18.04 LTS: I just need some hints/suggestions how a script could look like doing the following stuff: assuming I am in directory "base_directory" like xyz@mypc:~/base_directory$ within the "base_directory there... (1 Reply)
Discussion started by: dut42
1 Replies
FAKE-HWCLOCK(8) 					      System Manager's Manual						   FAKE-HWCLOCK(8)

NAME
fake-hwclock - Control fake hardware clock SYNOPSIS
fake-hwclock [ command ] [ force ] BACKGROUND
Many embedded Linux systems do not have a functional hardware clock. Either they simply don't have a hardware clock at all or they have a hardware clock but it is not usable (e.g. because Linux doesn't know how to use it or because no battery is present). This can lead to time moving backwards to some default value (often 1970) when the system is rebooted. Since lots of software assumes that time only moves forward this is a bad thing. NTP can (and should where practical) be used to sync with an external timeserver but it is not available early in the boot process and may be unavailable for other reasons. DESCRIPTION
fake-hwclock sets and queries a fake "hardware clock" which stores the time in a file. This program may be run by the system administrator directly but is typically run by init (to load the time on startup and save it on shutdown) and cron (to save the time hourly). If no command is given then fake-hwclock acts as if the save command was used. COMMANDS
save Save the time to the file. load Load the time from the file. If force is specified fake-hwclock will move the clock either backwards or forwards. Otherwise it will only move it forwards. FILES
/etc/fake-hwclock.data The file used to store the time /etc/init.d/fake-hwclock The init script used to run fake-hwclock on startup and shutdown /etc/default/fake-hwclock Settings file for the init script. /etc/cron.hourly/fake-hwclock Cron job used to save the time hourly ENVIRONMENT VARIABLES
FILE set the file used by fake-hwclock RETURN VALUES
1 is returned for invalid commands. 0 is returned in all other cases. BUGS
This approach can only provide a crude approximation of what a real hardware clock provides. Use of NTP or another method to keep the time in sync is strongly advised. Debian 5 April 2012 FAKE-HWCLOCK(8)
All times are GMT -4. The time now is 02:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy