I have a running program with different output files updating for given loops but for one of the files I want to keep all data (ie not override it) but always concatenate the last data to the previous ones. This needs to be done for given time intervals (lets say every 45 mins)
I don't have a specific code but what I want should be like this: the file to be checked is sss.temp
Code:
if sss.temp != sss.temp.old then
cp sss.temp sss.temp.old
cp sss.temp.dat sss.temp.dat.old
cat sss.temp.dat.old sss.temp > sss.temp.dat
else
do nothing
fi
sss.temp.dat should have all data at the end and I want the script to run this every 45 mins or 1hour for example
Moderator's Comments:
As pointed out before, please use CODE tags to clearly mark multi-line sample code, sample input, and sample output. Use ICODE tags for small code snippets to be formatted to appear in a line of text.
Last edited by Madiouma Ndiaye; 01-21-2014 at 04:36 PM..
Reason: Fix tags.
Do you mean that both files have the same i-node?
Do you mean that both files have the same size?
Do you mean that both files have the same contents?
Do you mean that sss.temp has been modified more recently than sss.temp.old?
The command:
Code:
cat sss.temp.dat.old sss.temp > sss.temp.dat
replaces the contents of sss.temp.dat with the contents of sss.temp.dat.old followed by the contents of sss.temp. If you want to append the contents of sss.temp.dat.old and sss.temp to the end of the current contents of sss.temp.dat, use:
If I understand your requirements correctly, this seems to do what you requested:\
Code:
sleep_time=$((45 * 60))
while true
do if ! cmp -s sss.temp sss.temp.old
then cp sss.temp sss.temp.old
cat sss.tmp.old >> sss.temp.dat
fi
sleep $sleep_time
done
but it seems that this would duplicate old data in sss.temp multiple times. I would think that sss.temp should be cleared after the data it contains has been added to sss.tmp.dat, but it isn't at all clear from what you've shown us what is writing into sss.temp. If it is a log file that is being held open by whatever is writing it, we can't just clear the old contents. And, if we do clear it, then the test at the start of the loop would look for a non-empty file rather than an unchanged file.
In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Dears,
I have a listfile contains list of files path.
i need to read the line of the listfile
mv the file to other directory
and update the listfile by deleting the lines of the listfile.
#!/bin/bash
target=/fstest/INVESTIG/Sadiq/TEST_ARCH
while read -r line || ];
do
mv $line... (19 Replies)
In the awk below I am trying to add a penalty to a score to each matching $1 in file2 based on the sum of $3+$4 (variable TL) from file1. Then the $4 value in file1 is divided by TL and multiplied by 100 (this valvue is variable S). Finally, $2 in file2 - S gives the updated $2 result in file2.... (2 Replies)
In the perl below I am trying to set/update the value of $14 (last field) in file2, using the matching NM_ in $12
or $9 in file2 with the NM_ in $2 of file1.
The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always
;... (4 Replies)
Right I have a MYSQL database with table1 with 3 columns, colA, colB and colC. I want to combine the data in the 3 columns into a 4th column names col_comb. Here's the SQL command that works:
UPDATE table1 SET `col_comb` = CONCAT( `colA` , ' - ', `colB` , ', ', `colC` );
So now I want this... (5 Replies)
hi all,
Please help me with rsync.
I configured rsync to preserve timestamps using the -a option.
When i renamed fileA to fileB on source machine I have to copies at the backup server.
The aim is to keep the most recent file.
fileA & fileB has same contents.
When i renamed fileB to... (2 Replies)
Hello
I need to write a shell script to update properties between files.
I have 2 files as follow:
file1
urlWebserviceCheckAddress^=McoConfigGlobal.commonGLOBALUrlWebservice
file 2
urlWebserviceCheckAddress=http://localhost:8080/tags
Both files containt the same properties... (1 Reply)