1824945 Members
3868 Online
109678 Solutions
New Discussion юеВ

Help in Scripting.

 
Anish Kumar
Occasional Contributor

Help in Scripting.

Hi,

I am very new to scripting.I need to develop one script that suit the following condition.

1. Intially i have two files test.log and newtest.log (contents are same).

2. The first file (test.log)will be keep on updating.

3. I need to take the difference (no of new lines added )and copy the new lines to another log file (say final.log).

4. Copy the test.log to newtest.log.

5. In the file one if a text is matching for say 4 or 5 times i need to add a new line in another log file.

Any suggestion or help will be appreciated.

Thanks in advance..

2 REPLIES 2
Dennis Handly
Acclaimed Contributor

Re: Help in Scripting.

Are the files sorted? If so you can use comm(1):
comm -23 test.log newtest.log > final.log
4) cp test.log newtest.log
5)
if [ ! -s final.log ]; then
if [ ! -f count.log ]; then
echo "5" > count.log
fi
match_count=$(< count.log)
(( match_count -= 1 ))
if [ $match_count -lt 0 ]; then
echo "No changes in 5 compares" >> another_log_file
match_count=5
fi
echo "$match_count" > count.log
fi
N,Vipin
Frequent Advisor

Re: Help in Scripting.


The 1-4 steps can be done using the following script. This will compare the files every 10 sec and send the difference to final.log


touch final.log
while true;do
diff test.log newtest.log >> final.log
cp test.log newtest.log
sleep 10
done

I am not clear the step 5, can you elaborate?