Problem with Find command urgent help!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with Find command urgent help!!
# 1  
Old 05-28-2012
Question 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.
Code:
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:
Code:
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,
# 2  
Old 05-28-2012
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
This User Gave Thanks to Neo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX and Linux Applications

problem with find command

Hi All, I want to search only files more than 60 min in particular directory but not in sub directories. with this command i am getting even sub directires also.Please and let me know how to get the files. $i=`find /home/n1013141/vijay -type f -mmin -60`; print $i; ... (6 Replies)
Discussion started by: bhas1285
6 Replies

2. Shell Programming and Scripting

URGENT HELP: problem with mv command

I was trying to move a file to a particular directory. In a hurry i forgot to give the dest directory, as below mv prod.log The file disappeared. :confused: Any idea where it might have moved??? And I have tried moving files based on date from one directory to another as below.... (1 Reply)
Discussion started by: siteregsam
1 Replies

3. Shell Programming and Scripting

problem in find command

I am facing problem in find command. I want to read all file names of a directory and write those names in a text file. My script is find /home/Pratik/src -type f -exec basename {} \; >> names.txt The script is working fine and writing all the file names but problem is file names are not... (5 Replies)
Discussion started by: pratikjain998
5 Replies

4. UNIX for Dummies Questions & Answers

Problem with Find command

Hi, I have a script below,which reads dates from No_weekandMonthend_dates.txt performs the copy operation. for i in `cat /tmp/No_weekandMonthend_dates.txt` do cd $Gerenimopath/ZH_LP find . -type f -name "$i_*.txt" -exec cp {} /home/gaddamja/TempLocal \; cd... (2 Replies)
Discussion started by: jagadish_gaddam
2 Replies

5. UNIX for Dummies Questions & Answers

very urgent..need of a script which finds a file without the use of find command..hlp

im a beginner in shell scripting and i need a script which will find a file in a given path without the use of find or grep command.......i need some kind of code.....plzzz plzzzz help me......ive tried n searched every where but i couldn't find the solution for my particular problem..... (4 Replies)
Discussion started by: mishi
4 Replies

6. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

7. Shell Programming and Scripting

Find command problem

Hi All, I am using following find command to delete the records older than 7 days but getting missing conjuction error.Kindly suggest: The command is: find <complete_dir_path> \(! -name usr -prune \) -type f -name "*.txt" -mtime +6 -print | xargs rm (11 Replies)
Discussion started by: visingha
11 Replies

8. Shell Programming and Scripting

Problem with Tail command --urgent pls

eg: If I execute an example tail statement to put rows from one file to another, it truncates some of the data. /carrier>wc -l IntIndA.txt 1918 IntIndA.txt /carrier>tail -1918 IntIndA.txt > test /carrier>wc -l test 132 test The tail command should copy 1918 rows to test file instead of... (4 Replies)
Discussion started by: subbukns
4 Replies

9. UNIX for Advanced & Expert Users

urgent: problem with find command

find / * -print > /var/tmp/updatedfilelist.txt 2>&1 i need to run the above file in cron. problem is, this process takes a long long long time to finish up. and even worse, it fills up the directory the output file is located in. i dont want the /var directory to ge filled up because of... (10 Replies)
Discussion started by: Terrible
10 Replies

10. UNIX for Dummies Questions & Answers

find command - Urgent Plz.

Hi, In my current directory, i have the following files: x1.dat x2.dat.gz x3.dat I want to use the find command and display only files which has *.dat and NOT *.gz extension files. Please help me out. Thanks, Kris Kart. (2 Replies)
Discussion started by: Kris_Kart_101
2 Replies
Login or Register to Ask a Question