Replace contents of a file

Hello,

I need help to replace a value by a new one.

I've got a script, that will get directory size in ko, then write the size value return in a log file :

The patch is given in crontab, and use with

$1

in the script.

I am looking for help to replace, after

:

the old value without to known what was the old value, by the new.

here is what look like the log file :

HOME_1:12345
HOME:45678
ACTARUS:45678

Thanks for your help.

Not sure I understand. Pls be more specific, post representative input and desired output ...

Hello RudiC,

the output is size in Ko given by

du -k

command.

I am looking for a command that will replace the old size value in log file by the new size. I just need the new value to replace the old value after the

:

in the log file.

ex :

when the script is looking the size of HOME_1, the new size (ex 1234578) will replace the old value 12345

Thanks

Do you want to change one value in the file? Perhaps this:-

for label in HOME_1 HOME ACTARUS
do
   du -ksx $label | read value rest
   ( grep -v "^$label:" filename ; echo "$label:$newvalue" ) > filename.tmp
   mv filename.tmp filename
done

Does that help? You've not been too clear on your problem.

Robin
Liverpool/Blackburn
UK

Hello,

sorry to be confused. I am trying to be as clear as I can :

I am trying the replace numbers by numbers in a log file that looks like :

dir2:123

I need to avoid to change anything in the log file except the size of the directory.

ex

du -k /dir1/dir2/

output

456 /dir/1/dir2/

so a shell command will replace my old size value with the today's one. This must work whatever the directory size is bigger or smaller the last value.

ex :

yesterday :

cat logfile.log
dir2:123

today

cat logfile.log
dir2:456

But I dont know how to do that.

Thanks.

I'm a little worried about the label part being a bit short. What happens if you have:-

/dir/1/dir2
/dir/2/dir2

The method I have given should work okay, but it uses the full directory name. Is that a problem?

Robin

Hello,

is there any way to just replace the new value with sed or awk without to create a temporary file ?

Thanks