|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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.loguse 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
|
||||
|
||||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| 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 |
|
|