Setting up files to the arrays one by one in BASH script
Hi All,
I have some log files as below Code:
# ls -rt | grep -v "Log_Viewer" | xargs -n1 1) mypc_monthly.log.1 then for second it should show recent weekly log file 2) mypc_weekly.log.2 then for all daily logs it should show as seniority wise which are created after recent weekly log file(mypc_weekly.log.2) file i.e 3) mypc_daily.log.7 next mypc_daily.log.8 next mypc_daily.log.9 next mypc_daily.log.10 and so on. For that I have made a script as below Code:
# cat Log_Viewer |
If you want data in an array in a certain order, then you need to place it in the array in the certain order.
|
Quote:
Code:
Log_File=( mypc_monthly.log.1 mypc_weekly.log.2 mypc_daily.log.7 mypc_daily.log.8 mypc_daily.log.9 mypc_daily.log.10 ) Thanks in advance for your kind help. |
Any help for the above script, please?
or how can I print to screen for all daily files which are created after latest weekly file? I don't want the below command which we know about those daily files, so we can print only those. Code:
ls -rt *.log.* | tail -n4 Waiting for your kind reply. |
hmmm ... i seem to be a little slow on the uptake for this one :( Looking at your original post, all the files would appear to already be in order ... no?
|
Hi Grail Guru,
May I expect any help for the above which all I have already explained? |
I am trying to help and although it seems clear to you, I am not getting the issue??
I understand that you want to place them in the array and you want a specific order. My issue is that it seems the files are already in the correct order, so what is it that I am missing? |
Using ls to get filenames is not a very good idea. While it might be ok for a quick one-shot operation, in a script you should use safer means.
Since the filenames already have names with regular patterns, you should be able to use globbing patterns instead. The only difficulty involved is that the numbers aren't zero-padded, so you'll have to use separate patterns for the single digit and double digit entries. Code:
Log_File=( It could also be compacted down into a single line with a bit of brace expansion. Code:
Log_File=( mypc_{monthly,weekly,daily}.log.{,1}[0-9] ) |
Hmm, after a bit more reading, I see that the requirement for the daily files are a bit more complex than I thought. But it's far from insurmountable.
Code:
Monthly_Logs=( mypc_monthly.log.{,1}[0-9] ) |
All times are GMT -5. The time now is 11:46 PM. |