Stuck in this shell script - please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Stuck in this shell script - please help
# 8  
Old 03-31-2011
First find the directories, then look for ".txt" files in each directory. We have also avoided the "for" construct which is unsuitable for open-ended lists or where filenames might contain space characters.

Code:
#!/bin/sh
system='/path/to/the/main/directory/Applications'

find "${system}" -type d -name DOC\* -print | while read DIR
do
        find "${DIR}" -maxdepth 0 -type f -name \*\.txt -print
done


Last edited by methyl; 04-06-2011 at 07:58 PM..
This User Gave Thanks to methyl For This Post:
# 9  
Old 03-31-2011
It can be done just with find.

Code:
find . -type f \( -path "*/DOC/*" -o -path "*/DOCS/*" \) -name "*.txt" -exec rename .txt .txtOld {} \;

This User Gave Thanks to rmtzcx For This Post:
# 10  
Old 03-31-2011
Only if find supports -path which isn't POSIX so many OS's may not have it.
# 11  
Old 04-01-2011
Try the following modification
Code:
find . -name DOC* | while read i
do
  find $i -type f -name '*.txt' -exec mv {} {}old \
  echo $i
done


Last edited by Franklin52; 04-07-2011 at 03:41 AM.. Reason: Please use code tags, thank you
# 12  
Old 04-06-2011
This is the only script that worked for me, in fact i want to do a further refinment to this code if it's possible, i would like to leave any *en*.txt files inside the DOC DOCS directories, i dont want to rename them. is this possible?

Quote:
Originally Posted by methyl
First find the directories, then look for ".txt" files in each directory. We have also avoided the "for" construct which is unsuitable for open-ended lists or where filenames might contain space characters.

Code:
#!/bin/sh
system='/path/to/the/main/directory/Applications'
 
find "${system}" - type d -name DOC\* -print | while read DIR
do
        find "${DIR}" -maxdepth 0 -type f -name \*\.txt -print
done

# 13  
Old 04-06-2011
Wrench

Just corrected my typo in the "-type" line.
Code:
#!/bin/sh
system='/path/to/the/main/directory/Applications'
 
find "${system}" -type d -name DOC\* -print | while read DIR
do
        find "${DIR}" -maxdepth 0 -type f -name \*\.txt -print
done

I don't have the Linux "find" command handy to test. The general answer is to build a condition into the command line using "find" syntax. There is an example earlier in this thread.
Totally untested, for illustration of the idea: "-a !" means boolean AND NOT .
Code:
find "${DIR}" -maxdepth 0 -type f \( -name '*.txt' -a ! -name '*en*.txt' \) -print

# 14  
Old 04-07-2011
I was mistaken, the cose below was the only thing that worked for me, but when i added

Code:
 \( -name "*.txt" -a ! -name "*/en/*" \)

it didnt work
and i got this error

find: paths must precede expression: (-name
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]


Quote:
Originally Posted by rmtzcx
It can be done just with find.

Code:
find . -type f \( -path "*/DOC/*" -o -path "*/DOCS/*" \) -name "*.txt" -exec rename .txt .txtOld {} \;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error in script, STUCK :(

Hi All, I am beginner in scripting. I wrote a simple script to perform some task. It seem to have some error in command line, Kindly somebody help. Thanks #!/bin/bash date cd /home/poojasaxena/Desktop/CMS/script/DataMCMatch function pause(){ read -p "$*" } FILE=$1... (22 Replies)
Discussion started by: nrjrasaxena
22 Replies

2. Shell Programming and Scripting

stuck on first script with sed issue

Hi, I'm developing my first bash script and have made good progress but stuck at this point. I've run sed on a text file to extract some data and have saved it into a variable e.g. $blah the variable contains emails as follows e.g. <a@b.com> <b@c.com> I'm now trying to edit... (2 Replies)
Discussion started by: newb1000
2 Replies

3. Shell Programming and Scripting

Script to Output Files That Have Got Stuck

Hi, I need to create a script that we will schedule to run say every 30 mins to check a directory for files that have been present for a set period of time. Situation we have is that we have an input folder where files are processed from and once processed they get moved to a done folder,... (1 Reply)
Discussion started by: everythingno
1 Replies

4. Shell Programming and Scripting

korn shell display lenght problem!!! i got stuck on this

Using the KSH, write a shell script called display_by_length, which takes an absolute pathname to a directory and displays all ordinary files in the directory ordered by their length; for each file listed, display the name of the file and its length - nothing else. Extend this script to take an... (1 Reply)
Discussion started by: babuda0059
1 Replies

5. Shell Programming and Scripting

Script Stuck In Loop

Hi all! Im trying to get this script to check for folders in a year/month/day folder structure and if the day doesnt exist then it makes the day. It will also make sure all of the days before todays date exist as well. This script assumes that the month and year folder already exist. It works... (3 Replies)
Discussion started by: Grizzly
3 Replies

6. Homework & Coursework Questions

i get stuck with this shell script code

i get stuck here . Anyone could check my work? the user type a group of upper case letters at a time with 0 at the end. Find and display the first letter in alphabetic order. For example, input of F, G, K, S, U, G, D, Q, P , the result should be D Any invalid input character (eg. #, $, 3, a,... (5 Replies)
Discussion started by: sbcvn
5 Replies

7. Shell Programming and Scripting

I am stuck in my script

Hi All I have script that find 777 dir with specific extension like .php .Now after finding all 777 directory i will place in httpd.conf using a directory directive ,Now i was not do that,if directory entry exitst in httpd.conf then script ignor it dont show me at stdout else if it dont find... (2 Replies)
Discussion started by: aliahsan81
2 Replies

8. UNIX for Dummies Questions & Answers

stuck with a script

Hi There I am pretty new to UNIX and have only been using it from a basic point of view,I now want to start using it and learning more , have got a whole lot of books and documentation from the web and am slowly learning.I have written a get script in windows :- lcd E:\MAIN\PRO\FILES\MAINDB... (1 Reply)
Discussion started by: FOCKER
1 Replies

9. Shell Programming and Scripting

simple script but am stuck

hey i am a bit stuck here. i just started work experience and i need to create a simple script which delete all files in a specify folder which are older then 2 days. :mad: i tried but it never works!!! anyone! i dont know much but unix since i mostly work on NT here but i dont wanna disapoint my... (2 Replies)
Discussion started by: GermanJulian
2 Replies

10. Shell Programming and Scripting

stuck on ksh script

hi, i need help to write script in korn shell that will display info. on system paging, system process table.system file table inf. thank you (1 Reply)
Discussion started by: neer45
1 Replies
Login or Register to Ask a Question