Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Find Replace 1

Status
Not open for further replies.

Neelimaix

Technical User
Jun 29, 2005
23
US
In 2022237391 14089876336 10 /10 02:39:55.833 PST Wed Nov 1 2006 02:41:15.833 PST Wed Nov 1 2006 80.0
In 9497860563 14089876279 10 /10 05:55:32.479 PST Wed Nov 1 2006 05:55:45.949 PST Wed Nov 1 2006 13.5
In 7344818101 14089876279 10 /10 05:26:35.666 PST Wed Nov 1 2006 05:30:02.176 PST Wed Nov 1 2006 206.5
In 2159101029 14089876038 10 /10 03:48:25.342 PST Wed Nov 1 2006 03:54:28.712 PST Wed Nov 1 2006 363.4
In 5178841550 14089875609 10 /10 03:29:23.876 PST Wed Nov 1 2006 03:36:55.286 PST Wed Nov 1 2006 451.4
In 8055095672 14089876036 10 /10 05:50:21.292 PST Wed Nov 1 2006 05:50:44.822 PST Wed Nov 1 2006 23.5
In n/a 14089874824 10 /10 05:13:46.469 PST Wed Nov 1 2006 05:14:56.089 PST Wed Nov 1 2006 69.6
In 8594895171 14089876988 10 /10 02:26:01.253 PST Wed Nov 1 2006 02:26:37.053 PST Wed Nov 1 2006 35.8
In 7027310456 14089876062 10 /10 04:43:12.651 PST Wed Nov 1 2006 04:47:26.661 PST Wed Nov 1 2006 254.0
In 8003240546 14089875820 10 /10 05:50:29.598 PST Wed Nov 1 2006 05:50:34.258 PST Wed Nov 1 2006 4.7
In 7048653741 14089876999 10 /10 00:01:38.702 PST Wed Nov 1 2006 00:02:17.132 PST Wed Nov 1 2006 38.4


Hi,,
I have a file with current date as "Wed Nov 1 2006"
I would like to change this with current date ,like "Thu Mar 13 2008"


the date keeps changing so i cant just find that specific date and replace with current date.

I would like to search the file and get those filed in the file and replace them with current date ..

like in the example i have identified the fileds as

awk '{print $8,$9,$10,$11}'

so can any body tell me how i can use awk to replace those extracted fileds with current date..

awk '/{$8,$9,$10,$11}/ /`date +'%a %b %d %Y'`/g'

i tried that command it didnt work,,,

please help..



 
` quotes are not processed inside single quotes. Also, awk does not understand sed-style search and replace syntax. Try this:

Code:
awk -v d=`date +'%a %b %d %Y'` '{$9=$10=$11=""; $8=d; print}'

Annihilannic.
 
Oops:

Code:
awk -v d="`date +'%a %b %d %Y'`" '{$9=$10=$11=""; $8=d; print}'

Annihilannic.
 
Anni,

Thanks for you help and i tried your command successfully.
but the out put is some what distorted with rest to the original., but i ll work on it.

fyi..
original report

In 9056952055 18888884449 10 /10 *04:59:57.999 PST Sun Mar 7 1993 *05:03:11.039 PST Sun Mar 7 1993 0.0
In 4122611500 18668253227 10 /10 *04:34:37.312 PST Sun Mar 7 1993 *04:36:58.186 PST Sun Mar 7 1993 0.0
In 3122187386 18007759540 10 /10 *03:46:29.281 PST Sun Mar 7 1993 *03:46:33.821 PST Sun Mar 7 1993 0.0
In 3178592640 18006323290 10 /10 *06:56:23.790 PST Sun Mar 7 1993 *06:58:38.970 PST Sun Mar 7 1993 0.0
In 8883669070 18662665999 10 /10 *05:55:38.451 PST Sun Mar 7 1993 *05:55:42.991 PST Sun Mar 7 1993 0.0

after: using awk:

In 9056952055 18888884449 10 /10 *04:59:57.999 PST Mar 7 1993 *05:03:11.039 PST Sun Mar 7 1993 0.0
In 4122611500 18668253227 10 /10 *04:34:37.312 PST Mar 7 1993 *04:36:58.186 PST Sun Mar 7 1993 0.0
In 3122187386 18007759540 10 /10 *03:46:29.281 PST Mar 7 1993 *03:46:33.821 PST Sun Mar 7 1993 0.0
In 3178592640 18006323290 10 /10 *06:56:23.790 PST Mar 7 1993 *06:58:38.970 PST Sun Mar 7 1993 0.0


spaces between the fields were gone ..
 
Yes, unfortunately that is a side effect of assigning new values to $n.

Try this instead to preserve white space:

Code:
awk -v d="`date +'%a %b %d %Y'`" '{sub($8" "$9" "$10" "$11,d); print}'

Note that if you are changing a date like '7' to '17' the line will end up being one character longer, in case that's important.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top