Find - a quick question

Find - a quick question

Post by Steve » Fri, 12 Nov 1999 04:00:00



Hi,

I'm trying to get the output of a find query into a 'for' statement.
I've tried the below, but with no luck.

find /dir/file* -mtime 1 | $NDATE

for i in $NDATE
do

...

I don't think i should be using the pipe command. I've tried all sorts of
ways.
Can anyone give me an idea of how to write this correctly?

The find query output /dir/file.999 where file.999 is the last modified.

regards

steve

 
 
 

Find - a quick question

Post by Rea » Fri, 12 Nov 1999 04:00:00


Steve W wrote;
# I'm trying to get the output of a find query into a 'for' statement.
# I've tried the below, but with no luck.
#
# find /dir/file* -mtime 1 | $NDATE

A quick answer (in ksh);

for filename in $(find /dir/file* -mtime 1)
do
   ...
done

Cheers,
Real

 
 
 

Find - a quick question

Post by Steve » Fri, 12 Nov 1999 04:00:00


Thanks for the replies to the last question. It worked.

I have another file which contains the following:

456 11/10/1999 1
20  11/10/1999 2
16  11/10/1999 3
3    11/10/1999 4
1    11/10/1999 5

I need to get it to output:

11/10/1999,456,20,16,3,1,0,0

I can't seem to get my head around only reading the date in once, then
reading
down the file for each $1. Also, this file sometimes contains 7 records. So
i need
to write something like if $1 = "" then print "0".
I think using the OFS = "," might work for the comma seperator?

regards

steve


>Hi,

>I'm trying to get the output of a find query into a 'for' statement.
>I've tried the below, but with no luck.

>find /dir/file* -mtime 1 | $NDATE

>for i in $NDATE
>do

>...

>I don't think i should be using the pipe command. I've tried all sorts of
>ways.
>Can anyone give me an idea of how to write this correctly?

>The find query output /dir/file.999 where file.999 is the last modified.

>regards

>steve

 
 
 

Find - a quick question

Post by Matthew Land » Fri, 12 Nov 1999 04:00:00



> Steve W wrote;
> # I'm trying to get the output of a find query into a 'for' statement.
> # I've tried the below, but with no luck.
> #
> # find /dir/file* -mtime 1 | $NDATE

> A quick answer (in ksh);

> for filename in $(find /dir/file* -mtime 1)
> do
>    ...
> done

> Cheers,
> Real

This can be dangerous though if there are file names out there with
spaces, tabs, returns, etc.  It might be a little safer to use a while
loop.  Although filenames with a return in them still might break.

find /dir/file* -mtime 1 |while read filename
do
  ...
done

 - Matt

--
_______________________________________________________________________

      Comments, views, and opinions are mine alone, not IBM's.

 
 
 

Find - a quick question

Post by Barry Margoli » Fri, 12 Nov 1999 04:00:00




>Thanks for the replies to the last question. It worked.

>I have another file which contains the following:

>456 11/10/1999 1
>20  11/10/1999 2
>16  11/10/1999 3
>3    11/10/1999 4
>1    11/10/1999 5

>I need to get it to output:

>11/10/1999,456,20,16,3,1,0,0

>I can't seem to get my head around only reading the date in once, then
>reading
>down the file for each $1. Also, this file sometimes contains 7 records. So
>i need
>to write something like if $1 = "" then print "0".
>I think using the OFS = "," might work for the comma seperator?

linecount=0
while [[ $linecount < 7 ]]; do
  read n date otherstuff
  if [[ $linecount = 0 ]]; then
    print -n $date,
  fi
  print -n ,${n:0}
done
print ''

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Find - a quick question

Post by Christopher J. Matter » Fri, 12 Nov 1999 04:00:00



> Steve W wrote;
> # I'm trying to get the output of a find query into a 'for' statement.
> # I've tried the below, but with no luck.
> #
> # find /dir/file* -mtime 1 | $NDATE
> A quick answer (in ksh);
> for filename in $(find /dir/file* -mtime 1)
> do
>    ...
> done

A better answer in ksh;

for filename in $(find "/dir/file*" -mtime 1)
do
  ....
done

Gotta quote those wildcards...

                Chris Mattern

 
 
 

Find - a quick question

Post by Barry Margoli » Fri, 12 Nov 1999 04:00:00





>> Steve W wrote;
>> # I'm trying to get the output of a find query into a 'for' statement.
>> # I've tried the below, but with no luck.
>> #
>> # find /dir/file* -mtime 1 | $NDATE

>> A quick answer (in ksh);

>> for filename in $(find /dir/file* -mtime 1)
>> do
>>    ...
>> done

>A better answer in ksh;

>for filename in $(find "/dir/file*" -mtime 1)
>do
>  ....
>done

>Gotta quote those wildcards...

Nope, Not in this case.  You need to quote it if it's the parameter to the
-name option, but not if it's the starting filename parameter to the find
command itself.

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

Find - a quick question

Post by Chris Costell » Fri, 12 Nov 1999 04:00:00



> for i in `find /dir/file* -mtime 1 `

   No.

find /dir/file* -mtime 1 -print |
while read line
do
        ...     # So we can work with files that have WHITESPACE!
done


 
 
 

Find - a quick question

Post by Christopher J. Matter » Fri, 12 Nov 1999 04:00:00





>>Gotta quote those wildcards...
> Nope, Not in this case.  You need to quote it if it's the parameter to the
> -name option, but not if it's the starting filename parameter to the find
> command itself.

Whups, you're right.  Not used to seeing wildcards used that
way in find.  In fact, quoting it makes it *fail*.  Sorry about that.

                      Chris Mattern

 
 
 

Find - a quick question

Post by Peter Sundstro » Sat, 13 Nov 1999 04:00:00


for i in `find /dir/file* -mtime 1 `

>Hi,

>I'm trying to get the output of a find query into a 'for' statement.
>I've tried the below, but with no luck.

>find /dir/file* -mtime 1 | $NDATE

>for i in $NDATE
>do

>...

>I don't think i should be using the pipe command. I've tried all sorts of
>ways.
>Can anyone give me an idea of how to write this correctly?

>The find query output /dir/file.999 where file.999 is the last modified.

>regards

>steve

 
 
 

1. I have a Quick Question, need quick answer.

I was looking at a computer.
It uses AMI Bios.
How compatible is AMI Bios with Linux?

Later...
 Dave.
--

--
David Falk          |"People always make the mistake of dismissing as untrue  

                    | their minds cannot readily grasp..." -- Lucius Apuleius
===============================================================================

2. unmounting floppy

3. Quick question about using "find" command.

4. Suggestions on r/o root fs

5. Quick question about finding PC specs

6. zmodem and stdin & stdout

7. Quick money - quick.mon [01/01]

8. minicom & screen

9. quick history find in bash

10. Quick quesition on "find"

11. Sun OS 8 -- accept error -- trying to find quick solution

12. newbie question about find - finding duplicate files

13. - Two questions: find files with specific permission, find files that belong to..