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.
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.
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,
remove the file named errorlog before entering to the loop.
try to give the full path of errorlog and check the errorlog in if condition with full path.
check for the existence or non-zero size of errorlog.