Visit Our UNIX and Linux User Community


Help with find/whereis C Shell Script

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Help with find/whereis C Shell Script
# 1  
Old 10-16-2009
Help with find/whereis C Shell Script

Use and complete the template provided. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:
Write a C Shell Script called "hunt" that takes a filename as it's single parameter and displays the full pathname of every file name that matches, searching downward from the current directory.

Besides the pathnames, hunt should print the number of directories,
and files searched.

Notes
-The argument could be a regular expression
-Commands find and whereis cannot be used
-No recursion. Instead use pushd and popd commands.

2. Relevant commands, code, scripts, algorithms:
pushd
popd

To input a reg exp:
set ptn = "$<"

To check a string against a reg exp:
-if($str =~ $ptn)...
-switch($str)
case $ptn:
...

endsw


3. The attempts at a solution (include all code and scripts):

Before I attempt the solution, I need someone to clarify what searching downward from the current dir would mean. Basically, I want to have a reg exp inputted and traverse from the curr dir through all sub directories testing all files against the reg exp? If someone could provide some pseudo code maybe using pushd and popd that would help me get started!

4. School (University) and Course Number:

CSUS
# 2  
Old 10-19-2009
Quote:
I need someone to clarify what searching downward from the current dir would mean.
I understand it as "searching " through the current directory and beneath (that means going through all present subdirs that are in current directory)
I suppose a good start would be to read the man pages of the command find...

Previous Thread | Next Thread
Test Your Knowledge in Computers #358
Difficulty: Medium
ibmawk is a fork of mawk, allowing applications to embed multiple parallel instances of awk interpreters.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and Replace in Shell script

Friends, I have more than 1000 lines in text file which needs to be converted as UPPERCASE by adding _ com.sun.url=www.sun.com com.ssl.port=808 com.ui.path=/apps/ssi Expected output com.sun.url=_COM.SUN.URL_ com.ssl.port=_COM.SSL.PORT_ com.ui.path=_COM.UI.PATH_ Thanks in... (4 Replies)
Discussion started by: baluchen
4 Replies

2. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

3. Shell Programming and Scripting

How to find out the shell of the shell script?

Hello My question is: How to find out the shell of the shell script which we are running? I am writing a script, say f1.sh, as below: #!/bin/ksh echo "Sample script" From the first line, we can say this script will run in ksh. But, how can we prove it? Can we print anything inside... (6 Replies)
Discussion started by: guruprasadpr
6 Replies

4. Shell Programming and Scripting

Shell Script Find in File

Right, noob to shell scripting, playing a round for practice, wrote the following but it doesn't seem to work as expected, how could I fix/improve this script? #!/bin/bash #set -v #set -x case $# in 1) echo Searching for $1 in '*'; find . -iname '*' 2>/dev/null | xargs grep "$1" -sl... (3 Replies)
Discussion started by: Pezmc
3 Replies

5. Shell Programming and Scripting

Find command in Shell Script

hi I am a newbee in Shell scripting (hardly 7 days) I have to execute a shell script which looks like this #!/bin/sh var1=`date +"%Y%m%d"` echo $var1 find . -name "$var1*" -exec mv {} Delete/ \; the find command in the script is running independently but when kept in this script it is... (24 Replies)
Discussion started by: sweetnsourabh
24 Replies

6. Shell Programming and Scripting

find command in shell script

Hi, dirs.conf fine contains below data /a/b/c/dir1|50 /a/b/c/dir2|50 /a/b/c/dir3|50 In a shell script I do as below while read file_rec do dir_name=`echo "${file_rec}" | cut -d "|" -f 1` purge_days=`echo "${file_rec}" | cut -d "|" -f 2` if then... (3 Replies)
Discussion started by: icefish
3 Replies

7. UNIX for Dummies Questions & Answers

difference of find,locate and whereis

hi guys, may i know the difference of find,locate and whereis ? (3 Replies)
Discussion started by: cromohawk
3 Replies

8. Shell Programming and Scripting

c shell script help with find

Okie here is my problem, 1. I have a directory with a ton of files. 2. I want to first get an input on how many days ago the files were created. 3. I will take those files and put it into another file 4. Then I will take the last # from each line and subtract by 1 then diff the line from the... (1 Reply)
Discussion started by: bigboizvince
1 Replies

9. Shell Programming and Scripting

NEWBIE: If and Find in shell script

Basically I have a shell script and i want to search the computer for a folder and if that folder exists i want to take some action. Not sure exactly how to do this most efficiently. Not very experienced....any help would be appreciated. (1 Reply)
Discussion started by: meskue
1 Replies

10. UNIX for Dummies Questions & Answers

whereis ls

When I execute the following: <pre> $ whereis ls ls: /usr/bin/ls /usr/ucb/ls $ pwd /bin $ ls -la ls -r-xr-xr-x 1 bin bin 18120 Oct 6 1998 ls </pre> ....but as you can see the 'ls' command is in the /bin directory AS WELL. Why doesn't show up on 'whereis'??? Thanks (3 Replies)
Discussion started by: guest100
3 Replies

Featured Tech Videos