Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-04-2012
Registered User
 
Join Date: Jan 2012
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Change time with current year

Hi,

How can i change the time below (red font) with the current year?

Thank You in advance.

hostname 2007-Feb-9 /u100/DEVCO/Patching a.log
hostname 2010-Jun-25 /u100/DEVCO/DumpCleaner a.log
hostname 2011-Jun-25 /u100/DEVCO/DumpCleaner/sample a.log
hostname 23:44-Jun-25 /u100/DEVCO/DumpCleaner/sample b.log
hostname 23:44-Jun-25 /u100/DEVCO/DumpCleaner/Recycle a.log
hostname 23:44-Jun-25 /u100/DEVCO/DumpCleaner/Recycle b.log
Sponsored Links
    #2  
Old 07-04-2012
itkamaraj's Avatar
^Kamaraj^
 
Join Date: Apr 2010
Posts: 3,025
Thanks: 33
Thanked 647 Times in 625 Posts

Code:
 
$ awk -v d=`date +%Y` '{sub(/[0-9][0-9]:[0-9][0-9]/,d)}1' input.txt
hostname 2007-Feb-9 /u100/DEVCO/Patching a.log
hostname 2010-Jun-25 /u100/DEVCO/DumpCleaner a.log
hostname 2011-Jun-25 /u100/DEVCO/DumpCleaner/sample a.log
hostname 2012-Jun-25 /u100/DEVCO/DumpCleaner/sample b.log
hostname 2012-Jun-25 /u100/DEVCO/DumpCleaner/Recycle a.log
hostname 2012-Jun-25 /u100/DEVCO/DumpCleaner/Recycle b.log

use nawk in solaris

use the code tag, next time

http://www.unix.com/how-post-unix-li...code-tags.html
The Following User Says Thank You to itkamaraj For This Useful Post:
lienyca (07-04-2012)
Sponsored Links
    #3  
Old 07-04-2012
jayan_jay's Avatar
Forum Advisor
 
Join Date: Jul 2008
Posts: 831
Thanks: 9
Thanked 185 Times in 176 Posts

Code:
$ sed "s,..:..-,$(date +%Y)-,g" infile
hostname 2007-Feb-9 /u100/DEVCO/Patching a.log
hostname 2010-Jun-25 /u100/DEVCO/DumpCleaner a.log
hostname 2011-Jun-25 /u100/DEVCO/DumpCleaner/sample a.log
hostname 2012-Jun-25 /u100/DEVCO/DumpCleaner/sample b.log
hostname 2012-Jun-25 /u100/DEVCO/DumpCleaner/Recycle a.log
hostname 2012-Jun-25 /u100/DEVCO/DumpCleaner/Recycle b.log
$

The Following User Says Thank You to jayan_jay For This Useful Post:
lienyca (07-04-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing field to current year keeferb UNIX for Dummies Questions & Answers 6 07-28-2010 05:08 PM
compare file modification date/time to current date/time Bill Ma Shell Programming and Scripting 5 08-27-2009 12:02 PM
read file and print additional rows till current year vasuarjula Shell Programming and Scripting 1 12-09-2008 02:13 AM
change year in the server krishan Solaris 1 05-09-2005 08:21 AM
change my current IP address tamemi IP Networking 4 03-10-2004 03:58 AM



All times are GMT -4. The time now is 04:27 PM.