Sponsored Content
Top Forums Shell Programming and Scripting Shell script (KSH) to list ONLY the ID of male employees whose last loging time was during the last Post 302598453 by ctsgnb on Tuesday 14th of February 2012 01:19:00 PM
Old 02-14-2012
Code:
# DEADLINE contains J-2 in a YYYYMMDDHHMM format

DEADLINE=$(perl -e 'printf "%s\n",scalar(localtime(time - 2*86400 ))' | awk -F"[ :]" 'BEGIN{
split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",d," ")}{
for(i=0;++i<=12;) if (d[i]==$2) m=i}{printf "%s%02d%s\n",$NF,m,$3 $4 $5}')

Code:
# Then build the date in YYYYMMDDHHMM from your file then performs check
# if M and last log within DEADLINE the || NR<4 is to ensure that the header is also displayed

awk -v d="$DEADLINE" '{split($4,l,"/");split($5,t,":")}$2=="M"&&((l[3]l[1]l[2]t[1]t[2])+0>d)||NR<4' yourfile

Code:
$ cat tst
Employee  Gender    NAME      Last Login
    ID                                       Time
-------------------------------------------------
210125       M         ABC         02/03/2012 08:07
451235       F         EFG         02/02/2012 16:53
241567       M         GHI         02/01/2012 14:03
314584       M         JKL         02/02/2012 12:43
123456       M         MNO         02/12/2012 23:00
654321       F         PQR         02/12/2012 20:10
210120       M         ZVF         02/03/2012 08:07
451230       F         UNM         02/02/2012 16:53
241560       M         IOP         02/05/2012 14:03
314580       M         UOP         02/04/2012 12:43
123450       M         MNN         02/13/2012 00:00
654320       F         PQP         02/11/2012 00:00
$ date
mardi 14 février 2012, 19:24:45 (UTC+0100)
$ DEADLINE=$(perl -e 'printf "%s\n",scalar(localtime(time - 2*86400 ))' | awk -F"[ :]" 'BEGIN{
> split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",d," ")}{
> for(i=0;++i<=12;) if (d[i]==$2) m=i}{printf "%s%02d%s\n",$NF,m,$3 $4 $5}')
$ echo $DEADLINE
201202121924
$ awk -v d="$DEADLINE" '{split($4,l,"/");split($5,t,":")}$2=="M"&&((l[3]l[1]l[2]t[1]t[2])+0>d)||NR<4' tst
Employee  Gender    NAME      Last Login
    ID                                       Time
-------------------------------------------------
123456       M         MNO         02/12/2012 23:00
123450       M         MNN         02/13/2012 00:00


Last edited by ctsgnb; 02-14-2012 at 03:00 PM..
This User Gave Thanks to ctsgnb For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix Shell Scripting -- update employees not present in input file

ALL, My shell script takes a employee file as input. I have to identify the list of employees not in the input file and update their status in the database. Approach I followed: by traversing through the input file add all the emplid's to a variable. update the status of employees not in... (2 Replies)
Discussion started by: sailussr
2 Replies

2. Shell Programming and Scripting

Help with ksh shell script

I am using /usr/bin/ksh in AIX I am reading the values of $dbname, $dbatmpdir/dbdir.$$, and $scope from a different file All I have to do is check if $dbname exists in file $dbatmpdir/dbdir.$$ and $scope should have a value either 'TABLE' or 'SCHEMA'. When I execute the following code. I am... (3 Replies)
Discussion started by: tenderfoot
3 Replies

3. Shell Programming and Scripting

what does this ksh shell script do?

Can someone tell me when the script is called, what does it do? I can't see it is going to run anything. (1 Reply)
Discussion started by: dp100022
1 Replies

4. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

5. Shell Programming and Scripting

time calculation in ksh script

I"m trying to calculate the duration of of backup within a ksh shell script but I get an error. #!/bin/ksh STTIM=`date '+%T'` EDTIM=`date '+%T'` .... .... echo "DURATION OF BACKUP: $((EDTIM - STTIM))" (5 Replies)
Discussion started by: Bperl1967
5 Replies

6. Shell Programming and Scripting

Help with ksh Shell Script

My goal is to create a script that will check if in a test or production environment. I wrote this script to check $host variable to check which server I'm on but this script does not work. if then BASE=/home/fmtest; export BASE else BASE=/home/fmprod; export BASE fi ... (5 Replies)
Discussion started by: Bperl1967
5 Replies

7. Shell Programming and Scripting

ksh script throwing arg list too long for mv cp wc - everything

i have a ksh script which internally calls another ksh script. this inner script has simple commands like shown in the code window. In the script im trying to do a mv - it fails with arg list too long. then i try to perform cp and cat - and both are failing with similar error. :wall: How is... (4 Replies)
Discussion started by: nyc68
4 Replies

8. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

9. UNIX for Dummies Questions & Answers

Help with ksh script to list files, cp it to another UNIX server

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (7 Replies)
Discussion started by: chococrunch6
7 Replies

10. Shell Programming and Scripting

Need Help in ksh Script to list files older than 365 days from specified directories

Requirement is to list the files older than 365 days from multiple directories and delete them and log the list of files which are deleted to a log file. so 1 script should only list files older than 365 days for each directory separately to a folder The other script should read these files... (7 Replies)
Discussion started by: prasadn
7 Replies
DATE(1) 						      General Commands Manual							   DATE(1)

NAME
date - print or set the date and time SYNOPSIS
date [-qsu] [[MMDDYY]hhmm[ss]] [+format] OPTIONS
-q Read the date from stdin -s Set the time (implicit for -q or a date string) -u Print the date as GMT -t Use this number of seconds instead of current time EXAMPLES
date # Print the date and time date 0221921610 # Set date to Feb 21, 1992 at 4:10 p.m. DESCRIPTION
With the -q flag or a numeric argument, date sets the GMT time and date. MMDDYY refers to the month, day, and year; hhmmss refers to the hour, minute and second. Each of the six fields must be exactly two digits, no more and no less. date always display the date and time, with the default format for the system. The -u flag request GMT time instead of local time. A format may be specified with a + followed by a printf-like string with the following options: %% % character %A Name of the day %B Name of the month %D mm/dd/yy %H Decimal hour on 2 digits %I Decimal hour modulo 12 on 2 digits %M Decimal minute on 2 digits %S Decimal seconds on 2 digits %T HH:MM:SS %U Decimal week number, Sunday being first day of week %W Decimal week number, Monday being first day of week %X Same as %T %Y Decimal year on 4 digits %Z Time Zone (if any) %a Abbreviated name of the day %b Abbreviated name of the month %c Appropriate date & time (default format) %d Decimal day of the month on 2 digits %e Same as %d, but a space replaces leading 0 %h Same as %b %j Decimal dey of the year on 3 digits %m Decimal month on 2 digits %n Newline character %p AM or PM %r 12-hour clock time with AM/PM %s Number of seconds since the epoch %t Tab character %w Decimal day of the week (0=Sunday) %x Same as %D %y Decimal year on 2 digits SEE ALSO
time(2), ctime(3), readclock(8). DATE(1)
All times are GMT -4. The time now is 11:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy