07-04-2008
The arithmentic on the dates will give you grief in the final "grep". Where hours and/or minutes fields are less than value 10, you will then need to convert integers with no leading zeros to strings with leading zeros.
If your intention is to find all entries in the log between two times (hour and minute on the same day) inclusive, the value of $z needs to be incremented by one.
The seconds fields ($s and $s1) appear to be surplus - the script as presented only needs the start and end times in hours and minutes.
I guess that "seq" is a program or enhanced shell function to generate numbers in a range. It is not a Bourne or Korn shell function. Beware that you could easily generate a command line which is too long by this method.
Alternative?
You could restructure the script to not do arithmetic on dates. Consider this simple example script "test2.sh" to process file "test2.txt" to extract lines between 0201 and 0203 inclusive using only character strings:
=======
test2.txt
=======
0101
0102
0103
0201
0202
0203
0301
0302
0303
======
test2.sh
======
cat test2.txt|while read MMDD
do
if [ "${MMDD}" -ge "0201" -a "${MMDD}" -le "0203" ]
then
echo "${MMDD}"
fi
done
=======
Execution
=======
# . ./test2.sh
0201
0202
0203
This method still needs enhancement to prevent false matches from grep when there is more than the 4 characters on a line! The exact layout of the logfile records and the position of the date on each line will dictate how write a script to do this match.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I would like to extract the following fields from the text file attached. I copied the contents from a pdf file and pasted them into the text file so I can use awk to extract them. The layout is as listed below.
name1,name2,name3,name4,Title,designation,nationality,dob,
national ... (1 Reply)
Discussion started by: mboro
1 Replies
2. Shell Programming and Scripting
Hi,
How can I debug an awk script?
I know that set -x can be used to debug a script. But this will not suite for awk scripts.
Can anyone help me?
Thanks in advance,
Chella (2 Replies)
Discussion started by: chella
2 Replies
3. UNIX for Advanced & Expert Users
Hi all,
i have two simple questions here...
1. i want to know that how to debug the UNIX shell script?
2. is there any way to handling the exception in UNIX shell script like oracle exception handling?
Please provide me those details it would be great help/
Thanks and Regards,
MPS... (3 Replies)
Discussion started by: psiva_arul
3 Replies
4. Shell Programming and Scripting
Hi All,
I have a script which is based on calculating current time
The script looks like this:
whenever i try to run the script it gives me error:Please advice wherther i have made mistake with if condition or with for loop??
The code :
set -x
#!/usr/bin/ksh
set -x... (7 Replies)
Discussion started by: usha rao
7 Replies
5. Shell Programming and Scripting
Hi,
When i run the script ./script.sh sun, this give me no output, it should give me the list of file.
If i run the script without the argument it should send me echo inside usage().
What is the problem?
please help
-Adsi
#!/bin/sh
ROOT_PATH=/net/icebox/vol/local_images/spins... (2 Replies)
Discussion started by: asirohi
2 Replies
6. Shell Programming and Scripting
Hi,
I have this script, searches and sets variables, then searches and sets more variables from multiple files.
I'd need to debug it a bit.
#!/bin/bash
egrep $1 `find | grep MAGT` >/tmp/resRA-$$
thread=`sed -n '/{0x/ {s/^.*{0x\(*\).*/\1/p;q}' /tmp/resRA-$$`
tag=`sed -n '/Tag=/... (5 Replies)
Discussion started by: Vitoriung
5 Replies
7. Shell Programming and Scripting
Hi I am relatively new in shell scripting Below is the code which i developed but for some reason, it keeps giving me error:
/apps/bss/BatchProg/at1/batch/scripts/ksh/TBATLC02.ksh: syntax error at line 41 : `then' unmatched
#!/usr/bin/ksh... (4 Replies)
Discussion started by: scripting_newbe
4 Replies
8. Shell Programming and Scripting
Hello,
is it possible to debug a script that is already running "on-demand"?
Somehow a command like "set -x" but once you've executed the script. And another one to disable debugging?
Thank you (0 Replies)
Discussion started by: asanchez
0 Replies
9. Shell Programming and Scripting
Hi,
I am trying to get squid up and running using a redirector process, and every time I try to load a web page, squid fails miserably.
Can some one with perl and squid knowledge take a look at these codes and tell if something is wrong here.
#!/usr/bin/perl
#
$| = 1;
@endings = qw/... (0 Replies)
Discussion started by: jamie_123
0 Replies
10. Ubuntu
How can I debug this script?
I want to know what it is doing or not doing?
#!/bin/bash
#
#
if ; then
# Do the thing you want before suspend here
echo "we are suspending." > /tmp/systemd_suspend_test.txt
elif ; then
# Do the thing you want after resume here
echo "and we are... (21 Replies)
Discussion started by: drew77
21 Replies
LEARN ABOUT ULTRIX
dwtopenhierarchy
DwtOpenHierarchy(3Dwt) DwtOpenHierarchy(3Dwt)
Name
DwtOpenHierarchy - Allocates a hierarchy ID and opens all the UID files in the hierarchy.
Syntax
#include <X11/DwtAppl.h>
Cardinal DwtOpenHierarchy(num_files, file_names_list, ancillary_structures_list,
hierarchy_id_return)
DRMCount num_files;
String file_names_list [];
IDBOSOpenParamPtr *ancillary_structures_list;
DRMHierarchy *hierarchy_id_return;
Arguments
num_files Specifies the number of files in the name list.
file_names_list
Specifies an array of pointers to character strings that identify the .uid files.
ancillary_structures_list
A list of operating system-dependent ancillary structures corresponding to such things as file names, clobber flag, and so forth.
This argument should be NULL for most operations. If you need to reference this structure, see the definition of IDBOSOpen-
ParamPtr in DwtAppl.h for more information.
hierarchy_id_return
Returns the search hierarchy ID. The search hierarchy ID identifies the list of .uid files that DRM will search (in order) when
performing subsequent fetch calls.
Description
The DwtOpenHierarchy function allows the user to specify the list of UID files that DRM will search in subsequent fetch operations. All
subsequent fetch operations will return the first occurrence of the named item encountered while traversing the UID hierarchy from the
first list element (UID file specification) to the last list element. This function also allocates a hierarchy ID and opens all the UID
files in the hierarchy. It initializes the optimized search lists in the hierarchy. If DwtOpenHierarchy encounters any errors during its
execution, any files that were opened are closed.
Each UID file specified in file_names_list can specify either a full directory pathname or a file name. If a UID file does not specify the
pathname it will not contain any embedded slashes (/), and it will be accessed through the UIDPATH environment variable.
The UIDPATH environment variable specifies search paths and naming conventions associated with UID files. It can contain the substitution
fields %L and %N, where the current setting of the LANG environment variable is substituted for %L and the .uid name passed to DwtOpenHier-
archy is substituted for %N. For example, the following UID path and DwtOpenHierarchy call would cause DRM to open two separate .uid
files:
UIDPATH=/uidlib/%L/%N.uid:/uidlib/%N/%L
static char *uid_files[] = {"/usr/users/me/test.uid", "test2"};
DRMHierarchy *Hierarchy_id;
DwtOpenHierarchy((DRMCount)2,uid_files, NULL, Hierarchy_id)
The first file, /usr/users/me/test.uid, would be opened as specified, as this file specification includes a pathname. The second file,
test2, would be looked for first in /uidlib/$LANG/test2.uid, and second in /uidlib/test2/$LANG.
After DwtOpenHierarchy opens the UID hierarchy, you should not delete or modify the UID files until you close the UID hierarchy by calling
DwtCloseHierarchy.
Return Values
This function returns one of these status return constants:
DRMSuccess The function executed
successfully.
DRMNotFound File not found.
DRMFailure The function failed.
See Also
DwtCloseHierarchy(3Dwt)
DwtOpenHierarchy(3Dwt)