Given this script called, say, list_days
(which, admittedly, takes advantage of some recent bash features that don't necessarily exits in other shells),
should do what you requested: print the porous list that you gave and fills in the holes from the start date (parameter 1) till EOMonth. While the mthdays function should be leap year proof, I added the 1 sec in the loop to make it leap second proof. On second thought, as this usually happens on the last day of a month, it will not be relevant...
Sorry RudiC, I really need a ksh version instead -
I've managed to insert the missing date string using sed and the script 'almost' works like how I want it with just a 'little' bit of problem. I will explain further as we get along.
The script now looks like below:
The content of the dates file that I am checking is as below:
The portion of the script that does the insert is as below:
The problem is like this when I am running the script. Today is 2015-06-20 and 2015-06-20 is missing from the dates file.
Unfortunately, the sed portion that appends the missing date assumes that 2015-06-19 exists and unfortunately, that date string does not exist either, so the insert of 2015-06-20 fails.
So the 'logic' that I need to apply is if date-1 does not exist in the dates file, I need to check for the last known date string prior to the current date that I am checking and use that as the prev_date to insert the missing date from. In this case, prev_date should be 2015-06-18 instead.
Basically, I do not really what to insert all the missing date into the dates file, only the ones from current date when the script was run until the end day of the current month.
At the moment, I am writing that logic as deducting one day at a time, grepping the dates file until I find a previous date that match and then do the sed, a very tedious and long winding routine but works. Maybe someone know of a better way of doing this
Not sure if I've explained it clearly
---------- Post updated 06-20-15 at 02:45 AM ---------- Previous update was 06-19-15 at 01:23 PM ----------
Hi,
Now this is very, very, very embarrassing. After thinking about it, I don't actually have to check for previous date, all I have to actually do is append the missing dates into the dates file and then do a range sort of the file?
So, now my problem is how do I do a range sort of the file?
For example, for the file below, how do I sort the date string in it and keeping the comments in its place at the same time.
How can i insert text at a particular line number or before/after a search pattern? The text i want to insert is of 8-10 lines including new line characters. I have stored this text in a separate file.
I know i can use
sed '{/pattern/|/regexp/|n}{i|a|c}<text to be inserted>' file
But i want... (7 Replies)
Hi,
I have a single value in insertval file. I want to load that value to database with the current date. I tried the below code but it is inserting <NULL> to database and echo $c is also null.
cat insertval | awk -F ' ' '{print $1}' > c
echo c=$c
data=`sqlplus -s user/pwd@hostname <<EOF ... (5 Replies)
Hi all,
I have a text file and I need to insert comma after every 2 digit.
-1-1-1-1-1-1-1-1-1 0 0 0
-1-1-1 2 0 0 3 311-1 0 1
-1-1 021 0 011-1-1 033 0I'd like to have this:
-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0
-1,-1,-1, 2, 0, 0, 3, 3,11,-1, 0, 1
-1,-1, 0,21, 0, 0,11,-1,-1, 0,33, 0Thanks for... (7 Replies)
I want to create a script that will set up key pairs from "thishost" to "remotehosts". I have a validate script in ~/<dir> that I need to prefix the generated key in the authorized_keys file, and I'm having to manually do this everytime.
Here are my attemps, perhaps you could perfect them for... (3 Replies)
Hi All,
Can someone pls help me to insert some text on a file.
my file contains something like below..
AKBULBU,
BALUMIL,
BATCH,BATCH
BOARROB,
BOTAKAT,
C57896,
CAKIOZE,
CHECMER,
CICOFRA,
CISZPAW,2194485
I want output as
USER_ID, LOGIN_ID (6 Replies)
Hi all,
I need to insert new text and change existing text in a file. For that I used the below line in the command line and got the expected output.
sed '$a\
hi...
' shell > shell1
But I face problem when using the same in script. It is throwing the error as,
sed: command garbled:... (4 Replies)
Dear Folks :),
I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp.
I can do this in vi editor by using this command :g/^/s//BBB_
e,g I have a file named as Test.dat and it containins below text:
michal... (4 Replies)
Hey guys, how do we take a line of text as an argument from a user and then insert it in the middle of a file irrespective of the number of lines in the file. I am trying to do this without SED or AWK. Inserting it in the beginning and at the end is easy, but i am trying to accomplish inserting... (6 Replies)
I need help, It's probably a joke for you, but I'm about to explode:
This is it:
I have a file which is created by batch, and includes a list of db files (with the complete path).
I want to use this list for a graph file - in order to exclude it from the daily backup. it means i need to add an... (2 Replies)