Command needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command needed
# 1  
Old 01-29-2014
Command needed

Hi,

I have the date as 20130101 and i need it to rephrased to 2013-01-01.

Any command which can do this.
# 2  
Old 01-29-2014
Code:
$ date -d"20130101" +"%Y-%m-%d" 
2013-01-01

$ date --date="20130101" +"%Y-%m-%d"
2013-01-01

go through man date

--edit--

if you don't know where to post thread post here
UNIX Desktop for Dummies Questions & Answers - The UNIX and Linux Forums
# 3  
Old 01-29-2014
Code:
mydate='20130301'
mydate=`echo "${mydate}" | sed 's,\(....\)\(..\)\(..\),\1-\2-\3,'`

# 4  
Old 01-29-2014
Code:
sed 's/./&-/6; s//&-/4'


--
Note: date --date or date -d is GNU date only...

Last edited by Scrutinizer; 01-29-2014 at 03:14 PM..
# 5  
Old 01-29-2014
Just so many methods to choose from... ;o)
Longhand...
Code:
Last login: Wed Jan 29 19:19:26 on ttys000
AMIGA:barrywalker~> mydate="20130101"
AMIGA:barrywalker~> echo "${mydate:0:4}-${mydate:4:2}-${mydate:6:2}"
2013-01-01
AMIGA:barrywalker~> _

This User Gave Thanks to wisecracker For This Post:
# 6  
Old 01-30-2014
The offering from wisecracker is probably easiest to understand and reuse for other purposes, but be aware that this is ksh93 or bash only. Older ksh probably won't support it.

The date functions are great if they work, but I haven't seen a good document on them yet. My man page for date is woeful. RHEL 6.3 even has:-
Quote:
The date string format is more complex than is easily documented here

To use an older ksh, try:-
Code:
mydate="20130101"
my_yyyy="${mydate%????}"
my_dd="${mydate#??????}"
my_mm="${mydate%$my_dd}"
my_mm="${my_mm#????}"

echo "${my_yyyy}-${my_mm}-${my_dd}"



I hope that this helps, if you need it.




Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help needed - UNIX command

The 'env' command prints out all of the environment variables and their values. Come up with a command that prints a list of environment variables whose names end with either 'NAME', 'DIR' or 'PATH'. What I've tried. $ env | grep '' Although it highlights the part of the variables... (8 Replies)
Discussion started by: edujs7
8 Replies

2. Shell Programming and Scripting

Linux command needed

guys im new here and i need help with some linux commands. filea has keyword on each line identity aaa bbb ccc i have following commands. egrep 'www.identity' ~/home/m3 >~/home/lopo2 wc -l file ~/home/lopo2 say lopo2 has 44 lines then output saved is identity 44 (1 Reply)
Discussion started by: ahfze
1 Replies

3. UNIX for Dummies Questions & Answers

Help with Tar command needed

Lets say I have 100 files. in those files I need to search specific word and I want to tar all those files at once. how can I do that?tar -cvf test.tar |grep house *.*Will it work? Please wrap all code, files, input & output/errors in CODE tags. It makes them easier to read and preserves... (2 Replies)
Discussion started by: ded325
2 Replies

4. UNIX for Dummies Questions & Answers

dd command help needed.

Hi I m creating a file which will serve as a virtual harddisk . I m using following command to create a file. #dd if=/dev/zero of=/tmp/Sample.dat bs=1M count=1024 I have following doubts regarding the operation. 1) In above example i m creating a file with byte size of 1M .However in... (1 Reply)
Discussion started by: pinga123
1 Replies

5. Shell Programming and Scripting

Perl command help needed

#!/bin/bash perl -nle' /(?:date|time|ref)/ and print join " ", /(?:date|time|ref)+/g or print ' inputfile Problem I have is that I want to delete words that are on the line of the 3 words above (date, time, and reference). However, I do not want to delete the words... (9 Replies)
Discussion started by: linuxkid
9 Replies

6. UNIX for Dummies Questions & Answers

Help needed with find command

Hi, I'm a complete noobie at UNIX and have hit a problem. I'm using the 'Talend' ETL tool to try and extract flat files from UNIX on a weekly basis. The dates are maintained in a control table and the appropriate folder has been mounted. I am using a component in 'Talend' which enable... (1 Reply)
Discussion started by: markee
1 Replies

7. Shell Programming and Scripting

Help Needed in understanding this command

Hi All, I search the forum for my query, Glad that got solution to it. But i really want to understand how does this command work. sed -e ':a' -e 's/\("*\),\(*"\)/\1~\2/;ta' Basically it is replacing all the comma(,) characters in between quotes with a tilde. Specially what does ':a' ,... (2 Replies)
Discussion started by: DSDexter
2 Replies

8. Shell Programming and Scripting

Solaris command needed.......

Hi can anyone tell me what command should i use to find the files which have been created within 24hrs in / . I tried with this find mtime 24 / But its not working. Pls let me know to solve the issue. (3 Replies)
Discussion started by: vinuvinod
3 Replies

9. Shell Programming and Scripting

help needed in fuser command

Hi all, I want to know if fuser command can be used to check if a file is being written or not??? Thanks In Advance Anju (1 Reply)
Discussion started by: anju
1 Replies

10. Shell Programming and Scripting

help needed in ls command

Hi all, i need to write an ls command which will pick up ind_01.txt/pak_01.txt from ind_01.txt pak_01.txt usa_01.txt files in a directory.. i wrote a ls command by storing ind and pak in 2 variables and listing it. Its working fine. But the pattern to be matched should be sent in... (1 Reply)
Discussion started by: anju
1 Replies
Login or Register to Ask a Question