ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh
# 1  
Old 02-09-2015
ksh

Hi Dears

kindly I am new here ...I want to ask your help ...

I want to write AWK command when enter date like 20140129 plus 9 then it gives me 20140207 I wrote below but the result was wrong

Code:
#!/bin/ksh

echo "please input the data:"
read a


if echo $a|awk '{if (substr($1,5,1)=="5") {substr($1,6,2)++} else {print "wrong"}}'


Last edited by vbe; 02-09-2015 at 04:32 AM.. Reason: spelling
# 2  
Old 02-09-2015
Hello shaho87,

Welcome to forums, kindly use code tags for commands/codes/inputs which you are using in your posts, as per forum rules.
Following may help you in same, if you a GNU date in your system.
Code:
date --date="20140129 +9 day"

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 02-09-2015
Hello Ravinder,

kindly , thanks a lot but i want to write script not to use the date.
# 4  
Old 02-09-2015
Hello Shaho87,

Could you please try following and let me know if this helps.
Code:
cat date_script.ksh
echo "Please enter a date in YYYYMMDD format:"
read DATE
echo "Please enter number of days which we want to take date from today's:"
read DAYS
date -d"$DATE +$DAYS day"

Following will be output after running the script.
Code:
./date_script.ksh
Please enter a date in YYYYMMDD format:
20140202
Please enter number of days which we want to take date from today's:
10
Wed Feb 12 00:00:00 EST 2014

Hope this helps.


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 02-09-2015
Hello Ravinder,

kindly,thanks a lot but i want to write a script do the operation manually i mean when we are type date the system directly know it but i want to build mine one thanks million for your helping.
# 6  
Old 02-09-2015
Hello shaho87,

Could you please go through following thread I have given a solution for getting date 1 day ago for NON GNU, kindly take it as a start up and then try frm your end and if you feel any problems please do let us know, we ca assist you.

Date variable - 1 in UNIX


Thanks,
R. Singh

Last edited by RavinderSingh13; 02-09-2015 at 03:48 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 7  
Old 02-09-2015
The script that you provided reads a line of data provided by a user into a shell variable named a. It then uses awk to see if the 5th character in the 1st string of non-blank characters is a "5" (presumably the 1st digit in a two digit month is a "5"), and if it is it gets the 6th character from that string, adds 1 to it, and throws it away; otherwise, it prints the string "wrong". In either case, your script then gets a syntax error from the Korn shell because you have an if statement with no matching then nor fi.

Is this a homework assignment?

If it isn't, can you explain (in English) what needs to be done to a string in the format YYYYMMDD to add 9 days to it and end up with a valid date in the same format. If you can't explain what your script needs to do to update your user's input string, you would be much better off using the tools on your system that are designed to perform date arithmetic instead of reinventing the wheel. Even if you can explain the steps required, please explain why you want to reinvent the wheel rather than use system tools that have been written to correctly handle these types of calculations in normal years, in leap years, and (in some cases) even across the conversion from Julian to Gregorian calendars.

And, please tell us what operating system you're using. An operation like this can be performed with a 1988 vintage Korn shell, but some things would be easier with a 1993 or later version of the Korn shell. What version of the Korn shell is installed as /bin/ksh varies from system to system.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help with ksh

I have the following file: one two three four man women yes no place togo bad sleep I need to move all lines that have only two words(columns) in a separate file and the rest in a separate file... I used : for $linecont in $(cat $filename); do echo $linecont > temp line1='cat... (7 Replies)
Discussion started by: daimne
7 Replies

2. Shell Programming and Scripting

ksh help

Hi, I have command like this with ooutput : unix>tnsping abc TNS Ping Utility for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Production on 17-AUG-2011 17:06:11 Copyright (c) 1997, 2007, Oracle. All rights reserved. Used parameter files: /opt/oracle/network/admin/sqlnet.ora ... (19 Replies)
Discussion started by: talashil
19 Replies

3. Shell Programming and Scripting

different behaviour for ksh and ksh -x

I'm getting different behaviour when executing below script in debug option. $ cat ss.ksh ff=$(pwd) echo " ff : $ff" $ ksh ss.ksh ff : /tmp $ ksh -x ss.ksh + + pwd ff= + echo ff : ff : I was getting this behaviour in my actuall script i'm able to reproduce this in simple script... (4 Replies)
Discussion started by: luckybalaji
4 Replies

4. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

Need help on ksh

1. Script using bash #!/bin/bash a=4294967296 (( b=$a / 2 )) echo "$a" echo "$b" *** output *** 4294967296 2147483648 2. Script using ksh #!/bin/ksh a=4294967296 (( b=$a / 2 )) echo "$a" echo "$b" *** output *** 4294967296 (3 Replies)
Discussion started by: gautam.shrestha
3 Replies

7. Shell Programming and Scripting

Help with KSH

Hi, I need some help with the Ksh scripting.... I have a Script call Mail.ksh which calls Crank.ksh which calls Readdates.ksh whoch calls mindiff.ksh the output of mindiff.ksh and Readdates.ksh are wirtten to a text file... Here is how each file is called or executed... ./Mail.ksh 30... (3 Replies)
Discussion started by: bhagya2340
3 Replies

8. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

9. Shell Programming and Scripting

tracing a ksh script within a ksh script

I normally trace a script with the ksh -x <script name> and redirect strderr to file. But if you have a script like the examble below...... vi hairy bear=`grep bear animals` if then ksh more_animals fi If I ksh -x hairy it won't trace "more_animals" unless I put a -x in it. Is... (1 Reply)
Discussion started by: shorty
1 Replies

10. Shell Programming and Scripting

executing a ksh script from another ksh script

Hi, I'm new to unix scripting.How can i call a script from another script. I have a.ksh and b.ksh .I have to call b.ksh from a.ksh after it is successfully exceuted. I tried using #!/bin/ksh -x in a.ksh and at the end i have used /path/b.ksh My problem is it is executing only a.ksh.it... (6 Replies)
Discussion started by: ammu
6 Replies
Login or Register to Ask a Question