Trying to capture empty variable.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Trying to capture empty variable.
# 1  
Old 07-26-2005
How to get the Date time when the file was created.

sorry for the title of this thread-
I figured out how to capture empty variable by using-
if [ $?fdate ]
then
........

This thread originally had two parts in it (one for capturing empty variable and the other to get the date time in 14 char format). Once I figured out the solution for the first part I edited the content. I changed the title too but it doesn't show up.

Anyway, my question is:
Is there any way to get the date and time when the file was created in 14 char (20050726105312) format?

ThankYou for any replies,
Radhika.

Last edited by radhika; 07-26-2005 at 12:08 PM..
# 2  
Old 07-26-2005
I tried to clip the date from ls -al command:

file_date=`ls -al test.txt | cut -f2-3 -d'0' | cut -f1-4 -d' ' `
echo filedate before conversion is: $file_date

I get the following result:
filedate before conversion is: Jul 26 09:53

I still don't know how to get it in 14 char date (20050726120530) format?

Appreciate any replies.
Radhika.
# 3  
Old 07-26-2005
Changing date to 14 char format

How about this ?

Code:
date --date="Jul 26 09:53" +%Y%m%d%I%M%S

It gave me

20050726095300

vino
# 4  
Old 07-26-2005
okay I modified my script to say:

"test.sh" 7 lines, 133 characters
fdate=`ls -al test.txt | cut -f2-3 -d'0' | cut -f1-4 -d' ' `
echo $fdate
mydate=`$fdate+%Y%m%d%I%M%S`
echo $mydate

I get the following error:
Jul 26 12:59
test.sh[4]: Jul: not found

Appreciate your reply.
Radhika.
# 5  
Old 07-26-2005
I got it....

filedate=`ls -al test.txt | cut -f2-3 -d'0' | cut -f1-4 -d' ' `
echo $filedate

date=$filedate
dte=`date +%Y%m%d%H%M%S`
echo $dte

Result is:
20050726135232

Thanks! Vino for the idea.
Regards,
Radhika.
# 6  
Old 07-26-2005
ls's time is not the file creation time, but rather the 'last modification' time.
look here
# 7  
Old 07-26-2005
ThankYou for the correction.

Although, in my case the file when created will be an empty file and will not be touched again.

Regards,
Radhika.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to capture system() function output in variable

How to capture system() function output in awk variable and the print that awk variable..... (8 Replies)
Discussion started by: bharat1211
8 Replies

2. Shell Programming and Scripting

How to check whether a variable is empty or contains some value?

hi, i want to check whether a a variable contains some value or is empty in a shell script. so if the variable contains some value i want to do some job and if the variable doesnt contain any value then i need to skip that job. here is a sample script read_filenames.sh contains ... (5 Replies)
Discussion started by: Little
5 Replies

3. UNIX for Dummies Questions & Answers

Capture Multiple Lines Into Variable As Of Standard Output

Hello All, I have the below script and output. cat test.sh #!/bin/bash -x logit() { echo " - ${*}" > ${LOG_FILE} } LOG_FILE=/home/infrmtca/bin/findtest.log VAR=`find . -type f -name "*sql"` logit $VAR Output: cat /home/infrmtca/bin/findtest.log -... (9 Replies)
Discussion started by: Ariean
9 Replies

4. Shell Programming and Scripting

AWK Script to Capture Each Line of File As Variable

Hi All, I'm working on creating a parts database. I currently have access to a manufacturer database in HTML and am working on moving all of the data into a MySQL db. I have created a sed script that strips out the HTML and unnecessary info and separates the script into one line for each field.... (3 Replies)
Discussion started by: dkr
3 Replies

5. Programming

capture the output of printf into another variable

Hi , I wonder if in java I can pipe the below output of the printf into a variable: System.out.printf(" This is a test %s\n", myVariable); I want to keep the output of the printf command to create my history array. Thanks. (2 Replies)
Discussion started by: arizah
2 Replies

6. Shell Programming and Scripting

Capture Process with highest CPU% in Variable

I am trying to capture the process on a red hat linux system with the highest cpu utilization into a variable. I have been playing with ps command but really do not think I am making the correct progress. For instance: top - 09:01:16 up 63 days, 18:29, 2 users, load average: 0.39, 0.49, 0.48... (5 Replies)
Discussion started by: jaysunn
5 Replies

7. Shell Programming and Scripting

How to capture value in shell variable from oracle sql?

Hi Friends, Do someone know how to capture value in a shell variable from oracle sql? Requirement : In a table we want to count the number of records and want to pass this value to a shell variable where it can be manipulated later. In ksh shell we open oracle connection from sqlplus. For... (1 Reply)
Discussion started by: sourabhsharma
1 Replies

8. Shell Programming and Scripting

[csh] How to capture output from a command and pass it on to a variable?

Hi there! I'm trying to write a script that will capture output from a command and assign it to a variable. Let's say, for example, I'd like to catch from inside the script whatever the following command outputs: ls *.aaa and put it into a variable "listoffiles". What I tried was: set... (3 Replies)
Discussion started by: machinogodzilla
3 Replies

9. Shell Programming and Scripting

Empty Variable

I am trying to assign list of files that created that day to a variable 'filename' filename=`ls -ltr |grep "Mar 6" | awk '{print$9}'` If there are no files created that day, my script just hangs, i need help with some login here. i am also trying to figure out a way to look for files that... (3 Replies)
Discussion started by: gundu
3 Replies

10. UNIX for Dummies Questions & Answers

Capture an empty key press...

I am trying to test input from the user, if they press enter with out an Y or N. I have the characheter thing sorted but when it comes to a blank or empty key press I am having trouble. if ; then clear echo "Sorry, that is an invalid choice!" exit fi I am using a KSH script in... (3 Replies)
Discussion started by: jagannatha
3 Replies
Login or Register to Ask a Question