Extract date / time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract date / time
# 1  
Old 11-11-2013
Extract date / time

Code:
[Tue Oct  1 13:32:40 2013]

How do i display in the below format without the brackets using shell script.

Code:
Tue Oct  1 13:32:40 2013

Moderator's Comments:
Mod Comment Please use CODE tags not only for all code segments, input samples, and output samples.

Last edited by Don Cragun; 11-11-2013 at 02:58 AM..
# 2  
Old 11-11-2013
Code:
date '+%a %b %d %T %Y'

# 3  
Old 11-11-2013
Date time

Can you please explain it.
# 4  
Old 11-11-2013
Code:
#cat hi
[Tue Oct  1 13:32:40 2013]

Code:
#sed -n 's/\[// ; s/\]//p' hi
Tue Oct  1 13:32:40 2013


Last edited by Don Cragun; 11-11-2013 at 03:57 AM.. Reason: Add CODE tags.
# 5  
Old 11-11-2013
Date time

I dont want to use SED for this. I want to use the date and cut command to display it.
# 6  
Old 11-11-2013
Use the command which praveen has give in previous post. To know more information about date use command below

Code:
man date


Last edited by Don Cragun; 11-11-2013 at 03:57 AM.. Reason: Add CODE tags.
# 7  
Old 11-11-2013
Where do you get this date format from? Output from a program, log-file etc
Code:
echo "[Tue Oct  1 13:32:40 2013]" | awk '{gsub(/^\[|\] *$/,x)}1'
Tue Oct  1 13:32:40 2013

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract date and time part from filename

Hi, I am facing one scenario in which I need to extract exact position of date and time from the name of the files. For example, Below is the record in which I need to extract position of YYYYMMDD,HHMISS and YYMMDD. Date and time variables can come more than once. I need to use these position... (13 Replies)
Discussion started by: Prathmesh
13 Replies

2. UNIX for Beginners Questions & Answers

How to extract date and time from filename?

Hi, I'm totally new in sell script and working with a shell code. I want to extract the date and time from the filenames. The filenames are different but all of them begins with WI_ SCOPE_: WI_SCOPE_DATA_CHANGE_2017-09-12_15-30-40.txt WI_SCOPE_BACK_COMPLETE_QUEUE_2017-09-12_15-31-40.txt... (5 Replies)
Discussion started by: Home
5 Replies

3. Shell Programming and Scripting

How to extract latest file by looking at date time stamp from a directory?

hi, i have a Archive directory in which files are archived or stored with date and time stamp to prevent over writing. example: there are 5 files s1.txt s2.txt s3.txt s4.txt s5.txt while moving these files to archive directory, date and time stamp is added. of format `date... (9 Replies)
Discussion started by: Little
9 Replies

4. Shell Programming and Scripting

To extract date and time separately from the file name

Hi., My current script extracts only if the date and time are in 3rd and 4th pos. #!/bin/bash echo "Enter the file name to extract the timestamp" read fname IFILE=$fname F=$IFILE IFS="_." f=($F) echo "Date ${f} Time ${f}" How to generalize the script to extract the... (3 Replies)
Discussion started by: IND123
3 Replies

5. Shell Programming and Scripting

Extract info from log file and compute using time date stamp

Looking for a shell script or a simple perl script . I am new to scripting and not very good at it . I have 2 directories . One of them holds a text file with list of files in it and the second one is a daily log which shows the file completion time. I need to co-relate both and make a report. ... (0 Replies)
Discussion started by: breez_drew
0 Replies

6. Shell Programming and Scripting

To extract data of a perticular interval (date-time wise)

I want a shell script which extract data from a log file which contains date and time-wise data and i need the data for a perticular interval of time...what can i do??? (3 Replies)
Discussion started by: abhishek27
3 Replies

7. Shell Programming and Scripting

How to extract date with time from file

Hi, I have a file where there is a date and time field, the format for it is yyyy-mm-dd hours:mins:sec the position of date field may vary anywhere in the line and it might be different and it is specified along with the variable AppTimeStamp how do i extract date and time both from the... (5 Replies)
Discussion started by: prash_b
5 Replies
Login or Register to Ask a Question