Hi,
I am writing a small unix command to substract one month from the MonthID.
If MonthID = 201301 the below script returns me 201212
Problem exists when MonthID=201307 and i run the above script and it returns 20136 instead of 201306
Help is appreciated to get the MonthID in correct format.
Moderator's Comments:
Please use ICODE tags, not QUOTE tags, when displaying in-line code, input, and output samples.
Last edited by Don Cragun; 05-07-2014 at 01:21 AM..
Reason: Fix tags.
Hi,
I am writing a small unix command to substract one month from the MonthID.
If MonthID = 201301 the below script returns me 201212
Problem exists when MonthID=201307 and i run the above script and it returns 20136 instead of 201306
Help is appreciated to get the MonthID in correct format.
Moderator's Comments:
Please use ICODE tags, not QUOTE tags, when displaying in-line code, input, and output samples.
Hi pinnacle,
I find this very confusing.
You haven't said what shell or operating system you're using, but from the [[ expression ]], I assume that you're not using a Bourne shell and that you are probably using bash or ksh.
But, your code sample doesn't define MonthID (or monthid). And the way you define MonthID in the description of what you're trying to do (with spaces around the equals sign in MonthID = 201301 won't work with any shell that I know of that supports [[ ... ]].
If my assumptions are correct:
You are using a Korn shell, a bash shell, or another shell that recognizes POSIX arithmetic expansions, and
you want to work with a variable named MonthID, not monthid,
then the following should do what you want MUCH more efficiently:
In fact, with a bash or ksh shell, it can be simplified further to:
Quote:
Originally Posted by Aia
substitute echo for printf
Hi Aia,
There is no need for the comma in $c,, and with some shells having a comma there will generate a syntax error.
These 2 Users Gave Thanks to Don Cragun For This Post:
You haven't said what shell or operating system you're using, but from the [[ expression ]], I assume that you're not using a Bourne shell and that you are probably using bash or ksh.
But, your code sample doesn't define MonthID (or monthid). And the way you define MonthID in the description of what you're trying to do (with spaces around the equals sign in MonthID = 201301 won't work with any shell that I know of that supports [[ ... ]].
If my assumptions are correct:
You are using a Korn shell, a bash shell, or another shell that recognizes POSIX arithmetic expansions, and
you want to work with a variable named MonthID, not monthid,
then the following should do what you want MUCH more efficiently:
In fact, with a bash or ksh shell, it can be simplified further to:
Hi Aia,
There is no need for the comma in $c,, and with some shells having a comma there will generate a syntax error.
Thanks Don Cragun !!
I am planning to use this as a single command in ETL tool (DataStage).
The operating system I am using is AIX.
Output of oslevel command gives : 6.1.0.0
Out of the 2 solutions that you provided only the first solution workson my side.
I am planning to use the 1st solution, but it I had a little concern, will this command work if unix admin apply some patch in future? Or should I be using the script that I created since it only uses very basic commands??
Appreciate your reply on this.
Also I have modified the command little bit to suit my needs as follows:
Note: MonthID here will be set by output of another ETL process.
I am planning to use the 1st solution, but it I had a little concern, will this command work if unix admin apply some patch in future? Or should I be using the script that I created since it only uses very basic commands??
Appreciate your reply on this.
Also I have modified the command little bit to suit my needs as follows:
Note: MonthID here will be set by output of another ETL process.
Appreciate your reply on my questions.
There shouldn't be any reason to avoid the above constructs on your current or future releases of AIX. You can also get rid of the 1st command in your script:
Hi,
I need all file names in a folder which has date >= 10th of last month,
Example
: files in folder
AUTO_F1_20140610.TXT
BUTO_F1_20140616.TXT
CUTO_F1_20140603.TXT
FA_AUTO_06012014.TXT
LA_AUTO_06112014.TXT
MA_AUTO_06212014.TXT
ZA_AUTO_06232014.TXT
Output:
AUTO_F1_20140610.TXT... (9 Replies)
Hello,
i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m
i need to write this script in php or bash or sh or mysql or perl in normal time o unix time
i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Hello All,
I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer.
Any ideas would be appreciated! (5 Replies)
Hi everyone,
I have a file containing one column and I want to subtract the first value (value of first line) from each line's value.
79304
99299
119294
139289
159284
179279
199274
219269
239264
259259
279254
299249
319244
339239
359234I tried working on an awk solution with... (1 Reply)
I've start and end time in two columns. How can I substract time from column 2 and column 1 and receive output in another file 'd' ?
$ cat c
12:55:04 2:03:56
2:03:56 3:20:17
14:00:00 13:05:00 (1 Reply)
Please guide if you know how to solve this.
I have a tab delimited INPUT FILE where each record is separated by -----
-----
ABC 4935402 4936680 Pattern=Cheers07080.1
ABC 4932216 4932368 Pattern=Cheers07080.1
ABC 4931932 4932122 ... (8 Replies)
We have a list of files (raw and jpeg types) with 2 different extensions (rw2 and jpg).
When there is both the raw and jpeg files, their file numbers must be the same (215 and 215, 218 and 218).
Sometimes there is only the jpeg file (216,217).
bla_215.rw2
bla_215.jpg
bla_216.jpg
bla_217.jpg... (9 Replies)
#!/bin/ksh
month=`date | cut -c5-8`
year=`date | cut -c24-28`
echo "$month"
echo "$year"
--- This gives me output as Feb and 2009
but now I want to substract the 1 month from the current script and want output as
Jan 2009.
Please note I have searched a lot on forum and found... (5 Replies)