|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
How to find first match and last match in a file
Hi All,
I have a below file: ================== 02:53 pravin-root 02:53 pravin-root 03:05 pravin-root 02:55 pravin1-root 02:59 pravin1-root ================== How do I find the first and last value of column 1. For example, how do I find 02:53 is the first time stamp and 03:05 is the last time stamp for user "pravin-root"? The no. of users can be large. I am trying a few options meanwhile... just posted here if someone already knows how to do it... Thanks and regards, Pravin Goyal |
| Sponsored Links |
|
|
|
|||
|
Hi All,
Thanks for your replies... I solved my problem... cut -f1 -d\ temp5_log > temp6_log t1=`head -n1 temp6_log` t2=`tail -n1 temp6_log` ./calc_time.sh $t1 $t2 I previously wrote a script calc_time.sh to calculate time difference.... ![]() Thanks and regards, Pravin Goyal |
|
|||
|
below perl code should throw some light on you. input: Code:
1 pravin-root 3 pravin-root 3 a 2 pravin-root 2 a 3 pravin1-root 2 pravin1-root 1 a output: Code:
a 1 a 3 pravin-root 1 pravin-root 3 pravin1-root 2 pravin1-root 3 code: Code:
my %hash;
open my $fh,"<","a.spl";
while(<$fh>){
chomp;
my @arr=split;
push @{$hash{$arr[1]}}, $arr[0];
}
foreach $key (sort keys %hash){
my @tmp=sort @{$hash{$key}};
map { print $key," ",$_,"\n" } @tmp[0,$#tmp];
} |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| using sed or grep to find exact match of text | risk_sly | UNIX for Dummies Questions & Answers | 5 | 10-23-2008 12:01 AM |
| List file in Dir and then match | aliahsan81 | Shell Programming and Scripting | 8 | 09-22-2008 07:05 AM |
| sed: find match and delete the line above | cstovall | Shell Programming and Scripting | 3 | 07-02-2008 11:31 PM |
| Find match in two diff file - local srv and remote server | amir07 | Shell Programming and Scripting | 0 | 03-07-2008 10:23 AM |
| combining 2 files with more than one match in second file | johnes42 | Shell Programming and Scripting | 5 | 12-04-2007 06:58 AM |