comparing file content differences

I need to write a script to find out if there are any .c files created/removed from the last time i monitored the files available. i first created a file to contain all the .c files available on the system. (ls *.c > file1)
I created another file using the same command.
I used the comm [-123] file1 file2 command to compare the differences.

Now i need to display the result in user readable form
e.g. These files has bee removed
file1.c
file2.c
These files have been created
file3.c
file4.c
OR
No files has been created/removed at all

How am i able to do that?

Try somothing like this :

comm -3 /path/to/previous_list /path/to/actual_list | \
awk '
$0 ~ "^\t" {
   created[++created_idx]=$1;
   next;
}
{
   removed[++removed_idx]=$1 ;
   next;
}
END {

   if (created_idx > 0) {
      print "These files have been created"
      for (idx=1; idx <= created_idx; idx++)
         print "  " created[idx];
   } else {
      print "No files have been created"
   }

   if (removed_idx > 0) {
      print "These files have been removed"
      for (idx=1; idx <= removed_idx; idx++)
         print "  " removed[idx];
   } else {
      print "No files have been removed"
   }

} '

Jean-Pierre.

doesn't seems to work. read the manual and understood what the awk command does, but ain very sure how it works. also i don't quite understand the 3rd line. i see that you uses the command like print and the way you uses the for loop. just need to clarify, can i use these command in the shell script? cause usually i used the echo command to print a message on the screen. I am running under the bourne shell or tcsh.

Take a look at this. Using diff and its <, > change properties.

#! /bin/sh
# rt.sh

if [[ $# -ne 2 ]] ; then
echo "Need just 2 files to compare"
exit 1
fi ;

# Take the diff by ignoring the blank and whitespaces.
diff -b -w ${1} ${2} > ${1}.diff
        if [[ $? -eq 0 ]] ; then
        echo "No files were added/removed"
        else
        echo "Files were added/removed"
        fi ;

# Process the diff file.
# A line might look like 
# < text-which-went-out
# > text-which-came-in

while read line
do
        if [[ ${line:0:2} == "< " ]] ; then
        echo ${line:2} is removed. 
        fi ;

        if [[ ${line:0:2} == "> " ]] ; then
        echo ${line:2} is added.  
        fi ;

done < ${1}.diff

rm ${1}.diff

Run it as ./rt.sh file1 file2

Remember the old file file1 should always be the first argument. Else, the logic would reverse.

vino

$0 ~ "^\t"
Selects records starting with a tabulation character.
Those records contain lines that are in file 2 only.

All the code from awk ' to the last ' is awk code (perhaps nawk or gawk on your system).
You can't use these commands directly in a shell script.

An example of my script execution :

/path/to/previous_list
file1.c
file2.c
file3.c

/path/to/actual_list
file2.c
file3.c
file4.c
file5.c

Output
These files have been created
file4.c
file5.c
These files have been removed
file1.c

The two files /path/to/previous_list and /path/to/actual_list must be sorted (needs by the command comm)

Jean-Pierre.