Need Help:Shell Script for Solaris to change the dates in a file by one week


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Help:Shell Script for Solaris to change the dates in a file by one week
# 1  
Old 11-19-2013
Need Help:Shell Script for Solaris to change the dates in a file by one week

I have to increase the date by one week in an input when script is executed in solaris. I was able to acheive this using ksh script that is working in Linux enivironment, when i execute the same script in Solaris i am getting below error:
Code:
/var/tmp\n\r-> ./script.ksh
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]

Script.ksh file contains below script: For this file and input file is provided "in.dat"
Script.ksh:

Code:
#!/bin/ksh
dIFS="$IFS"
IFS=''
rm -f a.out
cat in.dat | while read ln
do
 FirstPart=""
 DatePart=""
 RemPart=""

        #print $ln
        Reqstr=`echo $ln| grep -i "Created Before"`
 Str1=`echo $Reqstr | tr -d ' '`
 if [[ "${Str1}X" != "X" ]];then
 
         FirstPart=`echo $Reqstr| cut -c 1-51`
         DatePart=`echo $Reqstr| cut -c 52-62`
         RemPart=`echo $Reqstr| cut -c 63-80`

  NewDatePart=`date -d "$DatePart 7 days" +"%d-%b-%Y"`
  #echo "NewDate is $NewDatePart"
         echo $FirstPart$NewDatePart$RemPart >> a.out
 else

         Reqstr=`echo $ln| grep -i "Created After"`
  Str2=`echo $Reqstr | tr -d ' '`
  if [[ "${Str2}X" != "X" ]];then
 
   FirstPart=`echo $Reqstr| cut -c 1-50`
   DatePart=`echo $Reqstr| cut -c 51-61`
   RemPart=`echo $Reqstr| cut -c 62-80`
 
 
   NewDatePart=`date -d "$DatePart 7 days" +"%d-%b-%Y"`
   #echo "NewDate is $NewDatePart"
 
          echo ${FirstPart}${NewDatePart}${RemPart} >> a.out
  else
   echo $ln >> a.out
  fi
 fi
 IFS=''
done
cp a.out in.dat


in.dat file contains below content: When the above script.ksh is executed then the values of Creater After and Created Before dates should be increased by 7days

Code:
<?xml version="1.0" encoding="UTF-8"?>

<CrfReport>
  <SummaryReport command="execute" id="TC_2007_00_SUM_RPT_0011"
                 stylesheet_name="">
    <report_parameter name="Created After" value="
    <report_parameter name="Created Before" value="
    <report_option name="report_locale" value="en_US" />
  </SummaryReport>
</CrfReport>


Let me know if any information is needed.
Moderator's Comments:
Mod Comment Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Last edited by Don Cragun; 11-19-2013 at 01:31 AM.. Reason: CODE tags added to message; URGENT removed from Title.
# 2  
Old 11-19-2013
Your error is due to the fact that the default date utility on Solaris does not support the -d option. You need to install the GNU date utility and give the right path to the date utility. It may already be installed. Check under /usr/sfw/bin.
# 3  
Old 11-19-2013
I can see many files in the path you have told, but whats need be checked here?

I tried with this command
Code:
TZ=GMT-144 date +%d-%b-%Y

i am able to go back till 6 days but not up to 7 days.. any idea on this one?

Last edited by Franklin52; 11-19-2013 at 05:31 AM.. Reason: Please use code tags
# 4  
Old 11-20-2013
Quote:
Originally Posted by sriramanaramoju
I can see many files in the path you have told, but whats need be checked here?
If one of those files is named date, then see if it is the GNU date utility. If so, use it in your script instead of the default system date utility.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script change new format on the file.

Hi---Is there's way can write small shell script or perl script open "abc.txt" file and create new "new_abc.txt" file with format output below? Thanks cat abc.txt ###########################Readme############################### Contained with this README.TXT file are all of the file... (7 Replies)
Discussion started by: dotran
7 Replies

2. Linux

Get all the files from a FTP location with previous week's dates in the file names using Linux

I have a weird requirement where I have to get the files from a FTP(Lets say FTP1) location and place it on my current FTP(Lets say FTP2) location. The issue is, these are daily files (in a pattern Sales_YYYYMMDD_report.csv) and are placed every day on FTP1 and my process usually runs on Monday(eg.... (2 Replies)
Discussion started by: dhruuv369
2 Replies

3. Shell Programming and Scripting

Change value in a file using perl or shell script

hi, I have a local.conf file which has the first line TOPDIR = "/home/mvdev/workspace/boxer". I want to replace the value to "/home/common/workspace/mirror". I tried the following perl command that is perl -p -i -e 's/Path/path1/g' myfile.txt then sed... (7 Replies)
Discussion started by: amvarma77
7 Replies

4. Answers to Frequently Asked Questions

Finding the nth Particular Week in a Month – shell script

I see lot of request posted in internet to find out the day of nth week in a Month. example: what is the date of 3rd Sunday in October What is the date of 2nd Friday in June 2012 what is the date of 4th Saturday in January 2011..etc.. The below shell script is used to find out the... (1 Reply)
Discussion started by: itkamaraj
1 Replies

5. Shell Programming and Scripting

shell script to change the extension of a file

I have a directory that contains several files, out of which some files are have an extra extension for example file1.new.new.new file2.new.new.new file3.new.new.new file4.new.new.new i want to write a shell script that rename all such file with only single extension like file1.new... (7 Replies)
Discussion started by: mukulverma2408
7 Replies

6. Shell Programming and Scripting

Help with shell script for know when a file change it

Hi, IŽd like to know how to program a shell script for know when a file changes and based on that make another tasks all this in real time.. Thanks (2 Replies)
Discussion started by: mrios7
2 Replies

7. Shell Programming and Scripting

Change a line in a php file thanks to a shell script

Hi, I'm working on a script to make automatic the new releases of my website... However in this script I put all the css script in a single one. There's no rpoblem for that. My problem is when I want to change the header of my layout page to put instead of : $header.="<link rel=\"stylesheet\"... (2 Replies)
Discussion started by: lahabana
2 Replies

8. UNIX for Dummies Questions & Answers

Shell script to rename or change file extension case.

I searched the forum, but there was different type of rename. Hello. I have files in folder. Like: xxxxxxxx1.html or xxxxxxxx2.txt or xxxxxxxx3.tar.gz and how to rename or change file extension case to xxxxxxxx1.htm or xxxxxxx2.TXT or (5 Replies)
Discussion started by: Sheldon
5 Replies

9. Shell Programming and Scripting

Perl script to toggle through dates by week

Hi, I need help to toggle through dates on a weekly basis to be fed into a script as inputs. The format should be: yyyy/mm/dd (start) yyyy/mm/dd (end), where end date is 7 days increments. The date (start) would be input as an ARGV and would continue until current date. I can check... (2 Replies)
Discussion started by: subhap
2 Replies

10. Solaris

Time change next week - solaris 8 ?

Can anyone tell me does solaris 8 automatically update the time upon the daylight savings? (4 Replies)
Discussion started by: frustrated1
4 Replies
Login or Register to Ask a Question