![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Disk Usage in GB and Unix command to find the biggest file/folder | manas6 | UNIX for Dummies Questions & Answers | 8 | 07-30-2008 07:54 AM |
| Script to find a file in the other folder | ragavhere | Shell Programming and Scripting | 4 | 04-11-2008 02:38 AM |
| Parse the .txt file for folder name and FTP to the corrsponding folder. | MeganP | Shell Programming and Scripting | 3 | 07-03-2007 01:54 PM |
| Take a folder name and find it in another folder (Complicated) | hkhan12 | Shell Programming and Scripting | 5 | 09-06-2006 12:25 PM |
| how to differentiate a file from a folder in a FIND? | denysQC | UNIX for Dummies Questions & Answers | 3 | 06-06-2006 06:02 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Find a file in a folder-please help
HI ,
I have a very small requirement here. I need to find a file say which ends with .gz in a folder. If i found this file then i need to echo" file found" and do a word count of the file and if not i need to echo file not found and exit from the loop. i have written this script but i am only getting INPUT FILE FOUND FOR even if i don't have the ".gz " file in the folder. Can anyone help to see what is wrong in this script that i have written The script is below: ##!/usr/bin/sh FROM_DIR=/home/sandy; export FROM_DIR cd $FROM_DIR for filename in $FROM_DIR/*.gz do find . -name '$FROM_DIR/*.gz' if [ "$?" -ne 0 ] then echo " INPUT FILE NOT FOUND FOR ......." >> else echo " INPUT FILE FOUND FOR ......." >> fi wc -l *.cc3 done exit 0 |
|
||||
|
Unsure what you mean by doing a count, I am thinking you are wanting to put the file names found into a file called something.cc3.
Here's something that may help you... You could probably modify it for your needs. FOUNDFILE=/u/data/gzfilesfound rm ${FOUNDFILE} for filename in `ls ${FROMDIR}/*.gz` #If over or around 1000 files will not work do echo "${FILENAME}" >> ${FOUNDFILE} done if [ -s ${FOUNDFILE} ] then COUNT=`cat ${FOUNDFILE} | wc -l | tr -d " "` echo "There were ${COUNT} Files found" else echo "No files Found" fi |
|
||||
|
Hi benefactr,
sorry......... it was not .gz and but .cc3..............i am trying word count of the file what i trying do is trying to find the .cc3 file .....and if i find any i should do a word count of the file .......if not found then say find not found Please let me know if the above script that u gave is good enough or any changes are required |
|
|||||
|
bsandeep,
Your script will always find the files, as you are looping thru existing files in the directory: Code:
... for filename in $FROM_DIR/*.gz ... One way to check if a file exists: Code:
mFileName='YourFile'
if [ -f ${mFileName} ]; then
echo 'File '${mFileName}' exists number records = '`wc -w ${mFileName}`
else
echo 'File '${mFileName}' does not exist.'
fi
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|