Solved how to replace part of string

June 23, 2011 at 08:01:00
Specs: Windows 7
Hi, Unix Gurus,
I have a requirement as following:
my file format as following:
$Da=acc
$Dc=ccc
$C=0100
$$wc=1030
$$ldate=2000-01-01 00:00:00

file b
2011-01-01 00:00:00

I need a script to replace $$ldate from 2000-01-01 00:00:00 to the date from b file.

any body has some idea

thanks in advance


See More: how to replace part of string

Report •

#1
June 23, 2011 at 11:47:50
✔ Best Answer
This awk script using an equal sign as a field seperator accepts the date time variable as variable v1 and replaces the second field if the comparison is correct.

I leave reading the variable from file b into a variable to you:

#!/bin/ksh

var="2011-01-01 00:00:00"

awk ' BEGIN { OFS=FS="=" }
{
if($1 == "$$ldate")
     $2=v1
print $0
} ' v1="$var" filea


Report •

#2
June 23, 2011 at 12:41:16
Thanks Nails

This script works perfectly


Report •
Related Solutions


Ask Question