Problem with Find command urgent help!!

hi
I used find command to find some file names as per input from user. I used it for current directory. It was working fine. Now I tried with giving some other directory path. Its giving issues.
Here what I tried. Script will take input from user say 1_abc.txt, find the file and print list. if files are not there it will print No Files with this name message.
Finding files in the current Directory.

echo View Log files;    
echo Enter Log file name;
read -r filename ; find  "$filename"_*.* -type f ! -name ".*" 2>errorlog 
if [ -s errorlog ] ; then echo "No Files with this name"; fi 
echo Press Enter; 
read x;;

Then I tried with some different path, as:

echo View Log files;    
echo Enter Log file name;
read -r filename ; find /backup/test1/LogFiles/ "$filename"_*.* -type f ! -name ".*" 2>errorlog | awk -F/ '{print $NF}'
if [ -s errorlog ] ; then echo "No Files with this name"; fi 
echo Press Enter; 
read x;;

Now what is the problem with above code.

  1. Its printing files names with fullpath i.e., /backup/test1/LogFiles/1_abc.txt
    This is not required. I need to print only file names.
  2. The if statement is always in execution. Its always printing the "No Files with this name" statement.
    Simply its not working. I tried to use find with -P -H options but not of use.

Urgent help is needed.
Please help me to make it work.
Thanks,

Everyone at the UNIX and Linux Forums gives their best effort to reply to all questions in a timely manner. For this reason, posting questions with subjects like "Urgent!" or "Emergency" and demanding a fast reply are not permitted in the regular forums.

For members who want a higher visibility to their questions, we suggest you post in the Emergency UNIX and Linux Support Forum. This forum is given a higher priority than our regular forums.

Posting a new question in the Emergency UNIX and Linux Support Forum requires forum Bits. We monitor this forum to help people with emergencies, but we do not not guarantee response time or best answers. However, we will treat your post with a higher priority and give our best efforts to help you.

If you have posted a question in the regular forum with a subject "Urgent" "Emergency" or similar idea, we will, more-than-likely, close your thread and post this reply, redirecting you to the proper forum.

Of course, you can always post a descriptive subject text, remove words like "Urgent" etc. (from your subject and post) and post in the regular forums at any time.

Thank you.

The UNIX and Linux Forums

1 Like