New to UNIX ... Date parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New to UNIX ... Date parsing
# 8  
Old 01-22-2013
I typed linedat="12/12/2013"| echo ${linedat:6:4}/${linedat:0:2} on the command line and all I got back was /

How do I tell what version of bash I'm using

Last edited by Scrutinizer; 01-22-2013 at 12:29 PM.. Reason: code tags
# 9  
Old 01-22-2013
Code:
bash --version

# 10  
Old 01-22-2013
okay ... running
Code:
GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

Moderator's Comments:
Mod Comment Please use code tags
# 11  
Old 01-22-2013
Not sure what is wrong! You can use Scrutinizer's solution in post #3 or use an awk program:
Code:
echo $linedate | awk -F"/" '{ print $3,$1,$2 } ' OFS="/"
2013/12/21

# 12  
Old 01-22-2013
Trying to learn this on my own through trial and error, think it may be time to ask the big guns here ... will let you know .. thanks for your help ... This is not like Cobol Smilie
# 13  
Old 01-22-2013
Quote:
Originally Posted by MJKeeble
I typed linedat="12/12/2013"| echo ${linedat:6:4}/${linedat:0:2} on the command line and all I got back was /
[..]
The | should not be there.

bash/ksh93:
Code:
linedat=01/14/2013
echo "${linedat:6:4}/${linedat:0:5}"

# 14  
Old 01-22-2013
I thought that might be needed, I was trying to type it in native unix, so thought it might be needed to type on one line

---------- Post updated at 11:58 AM ---------- Previous update was at 11:41 AM ----------

okay ... so the code works in native unix, not sure why it is not working in my script. Back to the drawing board ... Thank you for your help!
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