I have written the below script to get the timestamp of each files and result is as below
Script
Input
Output
My requirement is store the output into an array.
ie array[1] should hold first row --> Wed 19 Jul 2017 06:10:13 AM EDT
array[2] should hold second row --> Wed 19 Jul 2017 06:10:13 AM EDT
Is it possible to store the entire output in single array through shell script
Thanks
Moderator's Comments:
Please use code tags
Last edited by jim mcnamara; 07-27-2017 at 09:19 AM..
I'm confused. On my Ubuntu 16.04 (Xenial) system the find options you use (i.e. -printf %Tc %p\n produces
Seven fields. You then pipe through an awk one-liner to print the first seven fields unchanged. Yet your required output shows only the first six fields?
So it occurs to me that the following may work for you (it does on my system with bash)
I got rid of the printing of the filepath and use an exclamation mark to separate the timestamps. IFS is similarly modified.
I hope that helps.
Andrew
---------- Post updated at 09:33 AM ---------- Previous update was at 09:21 AM ----------
Quote:
Originally Posted by apmcd47
I'm confused. On my Ubuntu 16.04 (Xenial) system the find options you use (i.e. -printf %Tc %p\n produces
Seven fields. You then pipe through an awk one-liner to print the first seven fields unchanged. Yet your required output shows only the first six fields?
Okay, after looking at the original post I realise you have an AM/PM marker which I don't. Difference in locale, I suppose. Anyway, my suggestion should still work for you.
Would it be safer to use stat to get a known format timestamp then convert it to one that meets your requirements rather than relying on the risks by using ls and being subject to locale etc.?
Perhaps thsi would help:-
If you build that into a loop called in by your find, that might do it.
(converting them only to display)
As for storing the values as an array, would you be better with an associative array? Have a look at the bash manual page for a description. Basically you could then map the filename to the timestamp as a pair of items keyed by filename (timestamp may not be unique)
Moving on from that, what do you plan to do with the timestamp values? if you are looking to sort them, process them, get items based on a date range, then you would be better storing them as either seconds from the Epoch or using a format such as YYYYMoDDHHMiSS so that it makes sense to numeric comparisons.
Computer code is not easy with human format dates, so one of the above could help tremendously. If you store the value as seconds, then you can display it whenever you need to by calling the date command above.
Hi Community,
Would love to get some quick help on below requirement.
I am trying to process mpstat output from multiple blades of my server
I would like to assign this the output to an array and then use it for post processing. How can I use a two dimensional array and assign these value
... (23 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)
Hi,
I want keep/save one command's output in an array and later want to iterate over the array one by one for some processing. instead of doing like below-
for str in `cat /etc/passwd | awk -F: '$3 >100 {print $1}' | uniq`
want to store-
my_array = `cat /etc/passwd | awk -F: '$3 >100 {print... (4 Replies)
I am trying to get userinput from stdin and store the lines in an array.
If i do this:
using a char **list to store strings
allocate memory to it
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv)
{
char *prog = argv;
char **linelist;
int... (5 Replies)
Hi Guys,
I have a file which is as follows:
1
2
4
6
7
I am trying to store these values in an array in bash. I have the following script:
FILE=try.txt
ARRAY=(`awk '{print}' $FILE`)
echo ${ARRAY} (3 Replies)
i have a file called file.txt having the following entries.
2321
2311
2313
4213
i wnat to store these values in a list and i want to iterate the list using loop and store it in another list (1 Reply)
hi i have a file as follows:
1
2
3
4
5
6
i want to store all these numbers in an array using awk.. so far i have:
awk '{for(i=1;i<=NR;i++) {a=$1}} END {for(i=1;i<=NR;i++) {printf("%1.11f",a)}}' 1.csv > test
however, i am getting all values as zero in the "test" file..... (3 Replies)
Hi All,
I need some help with arrays. I need to take input from the user for hostname, username and password until he enters .(dot) or any other character and store the values in the variable array.
I would further connect to the hostname using username and passwd and copy files from server to... (7 Replies)
All ..
I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced
code:
int cnt1;
char *t_array;
char *f_array;
for(cnt1=0; cnt1<1000; cnt1++)
{
t_array =... (1 Reply)