#!/bin/bash

# Check input parameters
if [ $# -ne 2 ]
then
  echo "Usage: $0 <user> <dir>"
  exit 1
fi

# Scan all files of the given user in the given folder
for file in $(find $2 -user $1 -type f); do

    # Check if file contains target string
    grep -e "^\*\*\*Da Modificare" $file

    # If that is the case edit and rename the file
    if [ $? -eq 0 ]
    then
      grep -v '^*\*\*Da Modificare' $file > /tmp/tmp$$.txt
      mv /tmp/tmp$$.txt $file"_mod"
      rm -f $file
    fi
done

exit 0
