Query regarding date field in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Query regarding date field in shell script
# 1  
Old 10-03-2009
Query regarding date field in shell script

Hi,

I wrote a simple shell script which accepts the input value yearmonth in the format YYYYMM and displays the date as YYYY-MM-DD.Day will be 01 always.Please find the code below

Code:
#!/bin/ksh
export yearmonth_date=$1
print_usage() {
   echo "usage: ${0##*/} <yearmonth_date> \n" \
               "      yearmonth_date        a yearmonth_date value in the format  YYYYMM" 1>&2
   exit 1
}
# check for valid parameters
if [[ $# -eq 1 ]]; then
     yearmonth_date =$1
else
   print_usage
fi
year=$(echo "$yearmonth_date" | cut -c1-4)
month=$(echo "$yearmonth_date" | cut -c5-6)
day='01'
curr_month_date=$year-$month-$day
echo $curr_month_date

Now when I execute I am getting the below mentioned error
Code:
>ksh get_curr_date.ksh 200904
get_rcurr_date.ksh[11]: yearmonth_date:  not found.
2009-04-01


Can anybody help me to resolve this error.?

Thanks

Last edited by Franklin52; 10-03-2009 at 10:03 AM.. Reason: Please use code tags!!
# 2  
Old 10-03-2009
You have a space before =

Code:
yearmonth_date =$1

Remove it.

Please use code tags in future, it makes things easier for everyone.

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

2. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

3. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

4. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

5. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

6. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

7. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

8. Shell Programming and Scripting

Convertion of Date Format using SQL query in a shell script

When I write Select date_field from TableA fetch first row only I am getting the output as 09/25/2009. I want to get the output in the below format 2009-09-25 i.e., MM-DD-YYYY. Please help (7 Replies)
Discussion started by: dinesh1985
7 Replies

9. Shell Programming and Scripting

shell script query

hi all i have a shell script for connecting in sybase env what i need is i have around 10 servers , i need to connect to all servers and retrive the database inforamtion in the servers and display them any one of u have it request to share it asap ! "QUERY TO Connect to all servers... (1 Reply)
Discussion started by: mvsramarao
1 Replies

10. Shell Programming and Scripting

Perl script to extract last date field (yyyy/mm/dd)

Hi Friends, I've a special requirement, even though I know how to implement this using shell scripting, current requirement is PERL, in which I'm not much familiar !!!. I've a record, which has around 200 fields, out of which I need to extract only one date value from the 97th field (this... (1 Reply)
Discussion started by: ganapati
1 Replies
Login or Register to Ask a Question