Problem with copying a date value to another variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with copying a date value to another variable
# 1  
Old 07-20-2010
Problem with copying a date value to another variable

Im having problem with copying/assigning the date which is stored in a vairable to another vairable.Below is the code

Code:
DT=`ls -ltr | tail -1 | awk '{print $5 $6}'` | date %Y%m%d # getting the date part from ls -ltr
echo ${DT} # prints the date
DT_2=DT # copying to another variable
echo ${DT_2 } # prints nothing

When i try to echo DT_2 it does not print anything.Is there any other way to get this printed? Or do we need to convert the date type to integer?

Im using KSH.

Last edited by Scott; 07-20-2010 at 11:45 AM.. Reason: Please use code tags
# 2  
Old 07-20-2010
Hi.

Code:
DT=`ls -ltr | tail -1 | awk '{print $5 $6}'`
echo ${DT} # prints the date
DT_2=$DT # copying to another variable
echo ${DT_2} # prints nothing # removed space before }

# 3  
Old 07-20-2010
Sorry thats a typo error. But still it doesn print.
# 4  
Old 07-20-2010
Please can you show us the output from

Code:
ls -ltr | tail -1

And the Operating System bit of.
Code:
uname -a

# 5  
Old 07-21-2010
below is the o/p of ls -ltr | tail

-rwxr--r-- 1 oned dstage 318 Jul 21 08:51 lst.ksh

And in the awk statement the argumenets shld be $6 $7
# 6  
Old 07-21-2010
Can you show exactly the code you are using now?

Please cut and paste, not type in - to avoid more "typos". Thanks.
# 7  
Old 07-21-2010
Below is the code im using. The final result that i get always is "DO NOT VALIDATE" as bate as no value in it, the else statement gets printed.

Code:
dte=`echo ls -ltr` | tail -1 | awk '{print $6 $7}' | date +%Y%m%d
echo ${dte}
bate=${dte}
echo bate value is ${bate}
cycle=20100702
if [[ ${bate} -gt ${cycle} ]]
then
echo VALIDATE
else
echo DO NOT VALIDATE
fi


Last edited by Scott; 07-21-2010 at 10:37 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace a parameter(variable) date value inside a text files daily with current date?

Hello All, we what we call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to... (1 Reply)
Discussion started by: pradeepp
1 Replies

2. Shell Programming and Scripting

Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T $s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \$from_date echo... (7 Replies)
Discussion started by: raj48
7 Replies

3. Shell Programming and Scripting

Rsync copying within recent date range?

As many will point out, one of the benefits of using rsync (without --delete) is that it will sync files between source and destination, but not delete files in the destination which HAVE been deleted in the source. Well, I have kind of the opposite problem and I'm wondering if there are date... (2 Replies)
Discussion started by: WIOP33
2 Replies

4. Shell Programming and Scripting

Copying a file using variable

Hi this is the code i am using copying a file by using a variable i have a file test.txt which contains 5 lines #!/bin/bash #SCRIPT: method2.sh #PURPOSE: Process a file line by line with redirected while-read loop. FILENAME=test.txt count=0 foldername=OUTPUT mkdir $foldername ... (5 Replies)
Discussion started by: Rami Reddy
5 Replies

5. Shell Programming and Scripting

LINUX ---> Add one date to a date variable

Hi All, I am trying to add one day to the busdt variable i am extracting from a file (DynamicParam.env). I am deriving the busdt as below. Is there any function which I can use to derive as below. If busdt=20120910, then the new derived variable value should be 20120911 If... (2 Replies)
Discussion started by: dsfreddie
2 Replies

6. Shell Programming and Scripting

date output store in variable problem

When I run following command date Output1 => Thu Sep 9 03:26:52 IST 2010 When I store in a varibale as a=`date` echo $a output2 => Thu Sep 9 03:27:02 IST 2010 The differnece is, it is trimming the space when I am storing the output in varibale. Output1 = Thu Sep 9 03:26:52 IST 2010... (2 Replies)
Discussion started by: pravincpatil
2 Replies

7. UNIX for Dummies Questions & Answers

Appending the current date on Copying the file.

Hi I have the data file in the one directory and i have to copy the file in the another directory with the timestamp. EX: /ab/cd/a.dat i need to copy this file to the another directory /ef/gh/. while am copying i need to append the current timestamp in the file like... (3 Replies)
Discussion started by: bobprabhu
3 Replies

8. Shell Programming and Scripting

copying a file without changing date stamp.

Hi, I am using the below copy command, to copy the file sbn to sbn1, cp sbn sbn1 but its changing the date stamp of file sbn1, but i dont want to change the date stamp of sbn1. Could you please help me out in this. (3 Replies)
Discussion started by: shivanete
3 Replies

9. Shell Programming and Scripting

Copying files created after a specified date/time

I need to write a script that copies files from one directory to another that were created after "today 6:30". This script will be NOT be ran at the same time each day. any help is appreciated. (2 Replies)
Discussion started by: jm6601
2 Replies

10. UNIX for Dummies Questions & Answers

Copying files with the latest date

Hi All, I have a situation where I need to copy the files having the latest date. For example I have a file by name bas100e1_jun05. I need to copy it to bas100e1. But when a file by name bas100e1_jul05 is put in the same directory the script should copy the file having the latest month which... (34 Replies)
Discussion started by: shashi_kiran_v
34 Replies
Login or Register to Ask a Question