Find -name "*.txt" in Korn Shell Script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find -name "*.txt" in Korn Shell Script
# 1  
Find -name "*.txt" in Korn Shell Script

The following find command works on the Korn Shell command line:

find . \( ! -name . -prune \) -type f -name "*.txt" -mtime +100

In the particular directory I'm in, the above find will list correctly the three text files that exist that haven't been modified in over 100 days:

./ep75150aA.txt
./ep13217a_rx_history11122001150339.txt
./ep13217a_rx_history12112001162013.txt
./Report2_ep75150a.txt


When that same find command runs within a Korn Shell script (against the same dir), it does not list the three files. It only shows:

drwxrwxrwx 2 7 devel 150528 Jul 18 11:28 .


What am I missing?

Thanks
# 2  
Try changing
"*.txt"
to
'*.txt'
# 3  
I was thinking I could get away with minimal detail on my first post, but, I was wrong - sorry about that. The script actually accepts parameters that will be used in the find command. I echo the find command to screen, and it 'looks ok" - see snippets below:

#!/bin/ksh
PURGEPATH=$1
DAYSOLD=\'$2\'
FILESPEC=\'$3\'
LOGINDICATOR=$4

###DAYSOLD=$2
###FILESPEC=\\$3 tried this
###FILESPEC=\"$3\" and this


...(The script switches to PURGEPATH)....

The find looks like this:

find . \( ! -name . -prune \) -type f -name $FILESPEC -mtime $DAYSOLD | xargs ls -ldrt >> $LOGFILE


I echo the 'variable populated' find command to the screen (and logfile), and it looks like:

find . \( ! -name . -prune \) -type f -name '*.txt' -mtime '+100' | xargs ls -ldrt


Finally, I put the 'hard-coded' find in the script, with -name '*.txt' (i.e. exactly the second find, above), and it worked! So, even though I echo the 'variable-populated' version to screen, and, it looks just like the 'hard-coded' version, the variable version ($FILESPEC, $DAYSOLD) does not work!


I hope I made that clear. My login shell is ksh. The script is ksh.
What is it about the use of the variables am I missing?


Thanks again!
# 4  
One solution is like this...
Code:
#! /usr/bin/ksh
TARGET=$1
eval find . -name \'$TARGET\' -print | xargs wc -l
exit 0

And the other other is to:
set -o noglob
at the top of the script. This affects everything though.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #817
Difficulty: Medium
In CSS, E[foo="bar"] matches an E element whose "foo" attribute value is exactly equal to "bar".
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

3. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

4. Shell Programming and Scripting

find error?? find / -name "something.txt" 2>/dev/null

why is this giving me errors? i type this in: find / -name "something.txt" 2>/dev/null i get the following error messages: find: bad option 2 find: path-list predicate-list :confused: (5 Replies)
Discussion started by: magiling
5 Replies

5. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

6. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

7. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies

8. Shell Programming and Scripting

Sorting problem "sort -k 16,29 sample.txt > output.txt"

Hi all, Iam trying to sort the contents of the file based on the position of the file. Example: $cat sample.txt 0101020060731 ## Header record 1c1 Berger Awc ANP20070201301 4000.50 1c2 Bose W G ANP20070201609 6000.70 1c2 Andy CK ANP20070201230 28000.00... (3 Replies)
Discussion started by: ganapati
3 Replies

9. Shell Programming and Scripting

korn shell "loops & arrays"

Hi, I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares. For example: file1 has a list of user ids (about 900) from the company's e-mail server. file2 has a list of user ids (about 50 or so) from... (7 Replies)
Discussion started by: muzica
7 Replies

10. Shell Programming and Scripting

Korn shell "select" command

I wish to display a full "ls -l" line per selection using the korn shell "select" command. ie : 1) -rw-rw---- 1 u22adm tbs 6144 Mar 15 10:29 y.dat 2) -rw-rw---- 1 u22adm tbs 4096 Mar 15 10:29 y.idx etc etc I can get spaces in : select f in "a a" "b b" "c c"; do... (2 Replies)
Discussion started by: mpegler
2 Replies

Featured Tech Videos