Corona corrected your problems. Consider a more generalized approach.
This is not production code. It could use more error checking, for example. I use it for quick and dirty stuff.
It breaks a file into an array of lines based on the \n character.
You could have it break on spaces or punctuation or whatever, in order to emulate creating an array of words in a file. Just change the delimiter in the split call. For large files create a larger result[] array.
You could call split again on a line and split the line by spaces + punctuation to get a word count, for example. You could add a regex call and split on just about anything.
This User Gave Thanks to jim mcnamara For This Post:
I try to get the month (of last save) and the filename into a variable, is this possible ?
something like this :
for month in `ls -la | awk '{print $6}'`
do
if ]
then
a=filename of the matching file
cp $a /Sep
fi
thanks,
Steffen (1 Reply)
Hi,
Hi, I run the command:
hostname to get the host back from the server: db201
Now, I need to take that result and set it to a variable. Can anyone help me with this?? I need to be able to use the same script on multiple servers so I do not want to hardcode the hostname result into... (1 Reply)
Hi
Can anybody tell me how can I dump the results of execution of a command into array form? For example, I want to execute:
and put each part of the result in an array element:
Thanks (2 Replies)
Hi,
In a kshell , i need to compare the results of two array .
each Non-match value should copy to a new array.
For example:
==========
Array one contain the following values:
A
B
C
Array two contain the following values:
C
F
A
E
After comparing this arrays , a new array should... (4 Replies)
How can I send the results of a query to a unix variable. I basically want to run a query then do some logic on the results. Trying to redirect the result into a variable I define in the script.
select count(*) as counter from table - nut to redirect the "count" returned from the query... (2 Replies)
I'm trying to add the paths of all the xml files in certain directories to an array. I want to use the array later in my code. Anyway, for some reason this isn't working. Any help would be appreciated.
Path_Counter=0
for result in "find * -name '*.xml'"; do
XmlPath="$result"
echo... (2 Replies)
Here is one I am baffled with; I have not used unix for a while and now that I am back it has been fun remembering and I have enjoyed it, for the most past. this is in ksh.
I need to search in a file for the line with X1 and cut columns 20-25, put them into a variable, added them (dollar... (3 Replies)
Requirement 1) I need to execute 15 SQL queries in oracle through linux script. All these query results needs to be stored in array variables.
Requirement 2) And these 15 queries needs to be executed in parallel.
Requirement 3) Once all the queries executed then the shell script should... (3 Replies)
for a in {1..100}
do
awk '{ sum+=$a} END {print sum}' a=$a file1 > file2
done
I know I will get only one number if following the code above, how can I get 100 sum numbers in file2? (2 Replies)
Good morning all,
This is the file name in question OD_Orders_2019-02-19.csv
I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies
LEARN ABOUT DEBIAN
unparse_time
PARSE_TIME(3) BSD Library Functions Manual PARSE_TIME(3)NAME
parse_time, print_time_table, unparse_time, unparse_time_approx, -- parse and unparse time intervals
LIBRARY
The roken library (libroken, -lroken)
SYNOPSIS
#include <parse_time.h>
int
parse_time(const char *timespec, const char *def_unit);
void
print_time_table(FILE *f);
size_t
unparse_time(int seconds, char *buf, size_t len);
size_t
unparse_time_approx(int seconds, char *buf, size_t len);
DESCRIPTION
The parse_time() function converts a the period of time specified in into a number of seconds. The timespec can be any number of <number
unit> pairs separated by comma and whitespace. The number can be negative. Number without explicit units are taken as being def_unit.
The unparse_time() and unparse_time_approx() does the opposite of parse_time(), that is they take a number of seconds and express that as
human readable string. unparse_time produces an exact time, while unparse_time_approx restricts the result to only include one units.
print_time_table() prints a descriptive list of available units on the passed file descriptor.
The possible units include:
second, s
minute, m
hour, h
day
week seven days
month 30 days
year 365 days
Units names can be arbitrarily abbreviated (as long as they are unique).
RETURN VALUES
parse_time() returns the number of seconds that represents the expression in timespec or -1 on error. unparse_time() and
unparse_time_approx() return the number of characters written to buf. if the return value is greater than or equal to the len argument, the
string was too short and some of the printed characters were discarded.
EXAMPLES
#include <stdio.h>
#include <parse_time.h>
int
main(int argc, char **argv)
{
int i;
int result;
char buf[128];
print_time_table(stdout);
for (i = 1; i < argc; i++) {
result = parse_time(argv[i], "second");
if(result == -1) {
fprintf(stderr, "%s: parse error
", argv[i]);
continue;
}
printf("--
");
printf("parse_time = %d
", result);
unparse_time(result, buf, sizeof(buf));
printf("unparse_time = %s
", buf);
unparse_time_approx(result, buf, sizeof(buf));
printf("unparse_time_approx = %s
", buf);
}
return 0;
}
$ ./a.out "1 minute 30 seconds" "90 s" "1 y -1 s"
1 year = 365 days
1 month = 30 days
1 week = 7 days
1 day = 24 hours
1 hour = 60 minutes
1 minute = 60 seconds
1 second
--
parse_time = 90
unparse_time = 1 minute 30 seconds
unparse_time_approx = 1 minute
--
parse_time = 90
unparse_time = 1 minute 30 seconds
unparse_time_approx = 1 minute
--
parse_time = 31535999
unparse_time = 12 months 4 days 23 hours 59 minutes 59 seconds
unparse_time_approx = 12 months
BUGS
Since parse_time() returns -1 on error there is no way to parse "minus one second". Currently "s" at the end of units is ignored. This is a
hack for English plural forms. If these functions are ever localised, this scheme will have to change.
HEIMDAL October 31, 2004 HEIMDAL