How to pick system time of the file placed on UNIX?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to pick system time of the file placed on UNIX?
# 1  
Old 06-07-2016
How to pick system time of the file placed on UNIX?

Hi ,I got one data file from external source and I have to load it in database through sql loader. I want to add 2 columns in database,one is file name and one is time of the file received on server.

Code:
-rwxr-x---    1 user user          238 Jun 03 16:32 90936264971326030616.ctr

From above case, I want one field as 'Jun 03 16:32' and one as "90936264971326030616" (file name without extension).

Thanks in advance







Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 06-07-2016 at 10:07 AM.. Reason: Added code tags.
# 2  
Old 06-07-2016
Not sure if your specifications requires the quotations or not but what about:

Code:
 awk '{print "\""$6,$7,$8"\"","\""substr($9,1,length($9)-4)"\""}' filename

Will produce:

"Jun 03 16:32" "90936264971326030616"
This User Gave Thanks to andy391791 For This Post:
# 3  
Old 06-07-2016
Quite sparse a request, no? What tools would be preferred? What would the data be used for, and how? How or where to store the data? In a file? In stdout (to be piped into sth.)? In shell variables?

Try
Code:
awk '{sub (/\..*$/, _, $NF); print $NF; print $(NF-3) " " $(NF-2) " " $(NF-1)}' file
90936264971326030616
Jun 03 16:32

This User Gave Thanks to RudiC For This Post:
# 4  
Old 06-08-2016
Hi All,

Thanks for your response

The actual requirement I have is to take the timestamp (file name here can be ignored), append it to all rows in the file so that it can loaded in database through sqlldr.

Once I extract the timestamp of the file in UNIX and pass it in one variable like $1 then I can further use the below command to make a new data file which I will load.
Code:
sed -e 's/$/   May 04 09:02/' summary_file.sql > Data_file.sql

I hope I am clear now.

I tried your suggested command :

File content is:-
***************
Code:
-rw-r-----    1 owner owner        976 May 04 09:02 summary_file.sql

Code:
cat summary_file.sql
REPORT_ID       REPORT_NAME     FILE_NAME       FILE_DESCR      RPT_GEN_DT      PARTNER_NAME    HQ_ID   SOLD_TO SOLD_TO_NAME    RO_SEGMENT      REPORT_CATEGORY SUB_CATEGORY    LOB     SUB_LOB FISCAL  REGION  SALES_ORG       EXT_PUB_IND     DATA_LOAD_TS    REPORT_GEN_IND  REPORT_GEN_TS   CREATE_TS       SUB_REGION_CD   summary_file1

Approach 1:-
***********
Code:
awk '{print "\""$6,$7,$8"\"","\""substr($9,1,length($9)-4)"\""}'  summary_file.sql

Output
*****
Code:
"PARTNER_NAME HQ_ID SOLD_TO" "SOLD_TO_"

It gives me 6,7 and 8th field.

Approach 2:-
***********
Code:
awk '{sub (/\..*$/, _, $NF); print $NF; print $(NF-3) " " $(NF-2) " " $(NF-1)}' summary_file.sql

It gives me output as :-
Code:
summary_file1
REPORT_GEN_TS CREATE_TS SUB_REGION_CD

It is not giving me time. It just picks up the last field in one line and other last 3 columns in one line.

Please help.



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules! It drastically improves readabilty of your post.

Last edited by RudiC; 06-08-2016 at 03:39 AM.. Reason: Added code tags
# 5  
Old 06-08-2016
An excellent example how incomplete and/or inaccurate specifications DO waste peoples' and requestor's time and effort!

To start from the beginning: What OS and shell version do you use? Do you have the stat or equivalent command at your disposal?
# 6  
Old 06-08-2016
Sorry for wasting your time ..its my first time to ask for a help like this..not sure what all info is required. Shell version is
Code:
/usr/bin/ksh

. It is an AIX server
# 7  
Old 06-08-2016
What be the stat equivalent on your system that can give the file's time stamp explicitly? (OK, if need be we can extract that from ls -l)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Arduino UNIX Time - Syncing Computer UNIX Time to Arduino Time with Python

Just finished a quick Python script to send the current unix time over to the Arduino from macOS, so in the absence of GPS or some other way to get the unix timestamp (epoch time) to the Arduino, I can get my macOS and Arduino UNO synced to within a second. Normally, when the Arduino starts... (9 Replies)
Discussion started by: Neo
9 Replies

2. Shell Programming and Scripting

Should pick latest file within past 3 days using UNIX script and perform steps in message below.

Hi , Can anyone help me how do perform below requirement in unix. Step1:we will receive multiple files weekly with same name(as below) in a folder(In folder we will have other files also def.dat,ghf.dat) Filenames: 1) abc_20171204_052389.dat 2)abc_20171204_052428.dat DON'T modify... (23 Replies)
Discussion started by: sunnykamal59
23 Replies

3. UNIX and Linux Applications

Pick Operating System

Anyone know anything about "Advanced Plus Operating Environment". Preferably release 10 Revision 522Gcd probably dated 2003. (4 Replies)
Discussion started by: jgt
4 Replies

4. Shell Programming and Scripting

UNIX file system to Linux file system migration

We would be migrating UNIX file system to Linux file system. We do have many directory and sub directories with files. after migrating unix to linux file system , i want to make sure all the files has been copied ? What would be the best approach to validate directory ,sub-directory and file... (1 Reply)
Discussion started by: balajikalai
1 Replies

5. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

6. Shell Programming and Scripting

Pick files after specified Time from a folder in Perl

Hi All I am stuck in a problem and wants help What i want to do is I have a directory(say name of that directory is outdir) In that directory(outdir) the files come after some gap of time by some processes. What i want to do is i want to list all the files in that directory after the given... (2 Replies)
Discussion started by: parthmittal2007
2 Replies

7. Solaris

getting time independent of system time in solaries

i am using function gethrtime() in sun solaries to get the time independent of the system time.Problem with this function is if we restart the system time will change to '0'.is there any other way to resolve this problem. thanks & regards suresh (3 Replies)
Discussion started by: suresh_rtp
3 Replies

8. Shell Programming and Scripting

System time comparison to fixed defined time

I have a requirement of checking the current system time and performing certain actions in a shell script. example: if the current system time is greater than 1400 hrs, then perform step 1,2,3 if the current system time is greater than 1000 hrs, then perform step 1,2 if the current system time... (2 Replies)
Discussion started by: zainravi
2 Replies

9. Shell Programming and Scripting

Date comparison in file to system time

I have a CSV (comma separated vaule) file whose entries resemble Area,\\ntsvsp02\vmcs\download\files\Areas.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00 Product,\\ntsvsp02\vmcs\download\files\items.dat,1,20090303,0,Import Complete,2009-03-02 04:23:00... (3 Replies)
Discussion started by: zainravi
3 Replies

10. UNIX for Dummies Questions & Answers

unix script that will pick up first 10 file

Suppose I have a unix file which contain a lost of 60 files like filename1 filename2 ... .. ... filename60 I want to write a unix script that will pick up first 10 files in first run 10-20 files in 2 run 20-30 files in 3 run 30-40 files in 4 run 40-50 files in 5 run 50-60 files in 6... (1 Reply)
Discussion started by: er_zeeshan05
1 Replies
Login or Register to Ask a Question

Featured Tech Videos