Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-30-2010, 07:58 AM   #1
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
date substitution problem

My infile:

despatching date 00/00/0000
despatching date 00/00/0000
despatching date 00/00/0000
despatching date 00/00/0000

My code:

echo -n " Enter Date as ddmmyyyy : "
read dat
echo $dat > xx
dd=`cut -c1-2 xx`
mm=`cut -c3-4 xx`
yy=`cut -c5-8 xx`
sed 's/00\/00\/0000/'$dd'\/'$mm'\/'$yy'/g' infile > outfile
rm xx

My Outfile:

despatching date 01/01/2010
despatching date 01/01/2010
despatching date 01/01/2010
despatching date 01/01/2010

Is there any shortcut for this especially in awk? Kindly guide me. Thank you.
Old 01-30-2010, 08:07 AM   #2
Senior Member
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653

read -p " Enter Date as dd mm yyyy : " DAY MONTH YEAR
sed 's/00\/00\/0000/'$DAY'\/'$MONTH'\/'$YEAR'/g' infile > outfile
seems to work ok

Old 01-30-2010, 10:12 AM   #3
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
Yeah! It will work, but the user will get confuse when giving the sapce between date,month,year. I mean they generally give date as 12122010 instead of 12 12 2010. Now gimmi some idea how to specify the fixed place to the date fields i.e.,
as soon as the user enters DAY number it should jump into the MONTH field and then next to YEAR field. Screen display as following...

Enter date as dd mm yyyy : <DAY> / <MONTH> / <YEAR>

I did something different using awk, but it is also almost same like your solution....

read -p " Enter Date as ddmmyyyy : " dat
awk '{
print $0
}' infile > outfile

but my request is there should be only
2 digit place for day
2 digit place for month
4 digit place for year

Last edited by visitnag; 01-30-2010 at 10:17 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 08:37 AM
sed whitespace substitution problem. arashi256 Linux - Newbie 18 07-17-2009 12:03 PM
adobe reader font substitution problem in Fedora 8 martin78 Linux - Software 0 11-13-2008 04:21 PM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 10:59 AM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 09:43 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:10 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration