New to UNIX ... Date parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New to UNIX ... Date parsing
# 1  
Old 01-22-2013
New to UNIX ... Date parsing

Hi ... extremely new to Unix scripting ... I have to get a date field from mm/dd/yyyy to yyyy/mm/dd format ... I have a variable that I want parsed. I don't seem to be doing it right?? Thanks.
# 2  
Old 01-22-2013
Using bash sub-string:
Code:
DT="10/01/2012"
echo ${DT:6:4}/${DT:0:2}/${DT:3:2}
2012/10/01

# 3  
Old 01-22-2013
Code:
echo "${var##*/}/${var%${var##*/}}"

Code:
IFS=/ read m d y << EOF
$var
EOF
echo "$y/$m/$d"

# 4  
Old 01-22-2013
Okay

Here is what I entered

Code:
 
linedate="12/21/2013"
lineyyyy=${linedate:6:4}
linemm=${linedate:0:2}
linedd=${linedate:3:2}
echo $linedate $lineyyyy/$linemm/$linedd

nothing is being echoed ??? Am I doing something wrong?

Last edited by Scott; 01-22-2013 at 12:10 PM.. Reason: Code tags
# 5  
Old 01-22-2013
What OS & shell are you using? Can you run below commands and post results?
Code:
uname
echo $SHELL

# 6  
Old 01-22-2013
Linux
/bin/bash

Told you I was new to this Smilie
# 7  
Old 01-22-2013
Works for me!
Code:
$ linedate="12/21/2013"
$ lineyyyy=${linedate:6:4}
$ linemm=${linedate:0:2}
$ linedd=${linedate:3:2}
$ echo $linedate $lineyyyy/$linemm/$linedd
12/21/2013 2013/12/21

I am using bash version 3.2.25
Code:
$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

2. UNIX for Beginners Questions & Answers

Getting the current time from a website and parsing date

I am trying to work on a script to grab the UTC time from a website So far I was able to cobble this together. curl -s --head web-url | grep ^Date: | sed 's/Date: //g' Which gives me the result I need. Wed, 06 Dec 2017 21:43:50 GMT What I need to is extract the 21:43:50 and convert... (4 Replies)
Discussion started by: allisterB
4 Replies

3. UNIX for Dummies Questions & Answers

Really need some help with Parsing files by date

Hi, I am new to Unix and need some help with a problem I have. I have been asked to ftp a file(s) from a directory to another system. I need to be able to allow the current days file to build and only send any other file across that is in the directory. I need a peice of code that will read... (3 Replies)
Discussion started by: darrenwg99
3 Replies

4. Shell Programming and Scripting

Parsing the date output

Hi fellows, I need to define a notification for SSL certificate expiration. My Command output is below: (this is the "Expiration Date") Tue Mar 15 09:30:01 2012 So, at 15th Feb (1 month before the expiration), a notification has to be triggered by a script or sth else. How can i set an... (5 Replies)
Discussion started by: oduth
5 Replies

5. Shell Programming and Scripting

Parsing Log File Based on Date & Error

I'm still up trying to figure this out and it is driving me nuts. I have a log file which has a basic format of this... 2010-10-10 22:25:42 Init block 'UA Deployment Date': Dynamic refresh of repository scope variables has failed. The ODBC function has returned an error. The database... (4 Replies)
Discussion started by: k1ko
4 Replies

6. Shell Programming and Scripting

parsing multi-date text file

Hi all: Trying to parse a log file of rsync activity to get the amount of date being transferred. The log file contains multiple dates and what I am trying to do is get the file sizes for the current date. What I have been trying to do is pipe it through awk but I am having trouble retrieving... (1 Reply)
Discussion started by: raggmopp
1 Replies

7. Shell Programming and Scripting

Compare date from db2 table to yesterday's Unix system date

I am currently running the following Korn shell script which works fine: #!/usr/bin/ksh count=`db2 -x "select count(*) from schema.tablename"` echo "count" I would like to add a "where" clause to the 2nd line that would allow me to get a record count of all the records from schema.tablename... (9 Replies)
Discussion started by: sasaliasim
9 Replies

8. UNIX for Dummies Questions & Answers

Parsing Date to a file name

Hi All There is a file "apple_2008-08-15.log". I have to use grep on this file to collect my test log. There are 45 such files. Is there a command that I can use to dynamically substitute the daily date as part of the file name? As of now Iam renaming the file to the new date and running my... (6 Replies)
Discussion started by: pk_eee
6 Replies

9. Shell Programming and Scripting

Date parsing into string, help!

I have a file that was created yesterday that I want to access... daily.log2008-02-16 I am using... curr_time=`date +"%Y %m %d"` yesterday=`./datecalc.ksh -a $curr_time - 1` the value for yesterday is now "2008 2 16" in ksh, how do I transform the string "2008 2 16" into "2008-02-16" (5 Replies)
Discussion started by: martyb555
5 Replies

10. Shell Programming and Scripting

parsing a system log file via the 'date' command

Hello, I'm trying to update some scripts here that parse our system logs daily. They report information just fine... but they just report too much info. Specifically, if there's been some failed login attempts on several different days (say Monday and Tuesday), when I get the report from... (5 Replies)
Discussion started by: cjones
5 Replies
Login or Register to Ask a Question