Unix Shell - Help on ls

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > August 2007 > Help on ls





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Help on ls
pincopallo_it@yahoo.it

2007-08-29, 7:17 am

a command like
ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
does not work when there are many files

How can i substitute it ?

Chris

2007-08-29, 7:17 am

On 29 Aug., 10:47, pincopallo...@yahoo.it wrote:
> a command like
> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
> does not work when there are many files
>
> How can i substitute it ?



Maybe this can help you to:
set -o xtrace

After you have set this option every command is displayed how the
shell interpretes it...

Maxwell Lol

2007-08-29, 7:17 am

pincopallo_it@yahoo.it writes:

> a command like
> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
> does not work when there are many files
>
> How can i substitute it ?


Here's one way

cd $NHBPWDBATCH
ls PWD50*.TXT >> appopippo 2>/dev/null

or

find $NHBPWDBATCH -name 'PWD50*.TXT' >> appopippo 2>/dev/null


pgas

2007-08-29, 7:17 am

On Aug 29, 1:45 pm, Maxwell Lol <nos...@com.invalid> wrote:
> pincopallo...@yahoo.it writes:
>
>
> Here's one way
>
> cd $NHBPWDBATCH
> ls PWD50*.TXT >> appopippo 2>/dev/null


This doesn't solve any problem, and on the contrary introduce a bug
if the cd fails.
Plus the output is different.

>
> or
>
> find $NHBPWDBATCH -name 'PWD50*.TXT' >> appopippo 2>/dev/null


This one avoids the expansion of the filenames on the "command line",
and thus will indeed
work with any number of files.
Just take care that 1) it's recursive, 2) if "$NHBPWDBATCH" has a
space it's a good idea to double quote it

with bash (and probably with other shells with a printf builtin) you
can also do:

shopt -s nullgob # so that the expansion returns nothing if no file
are found.
printf "%s\n" "$NHBPWDBATCH"/PWD50*.TXT >> appopippo

Bill Marcum

2007-08-29, 7:17 am

On Wed, 29 Aug 2007 01:47:28 -0700, pincopallo_it@yahoo.it
<pincopallo_it@yahoo.it> wrote:
>
>
> a command like
> ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null
> does not work when there are many files
>
> How can i substitute it ?
>

ls $NHBPWDBATCH | grep 'PWD50.*\.TXT' >> appopippo 2>/dev/null


--
The goal of science is to build better mousetraps. The goal of nature
is to build better mice.
Michael Tosch

2007-08-29, 1:20 pm

Bill Marcum wrote:
> On Wed, 29 Aug 2007 01:47:28 -0700, pincopallo_it@yahoo.it
> <pincopallo_it@yahoo.it> wrote:
> ls $NHBPWDBATCH | grep 'PWD50.*\.TXT' >> appopippo 2>/dev/null
>


More precise is:

\ls $NHBPWDBATCH 2>/dev/null | grep '^PWD50.*\.TXT$' >> appopippo

and with the OP's full-path listing is:

\ls $NHBPWDBATCH 2>/dev/null |
sed -n 's#^PWD50.*\.TXT$#'$NHBPWDBATCH'&#p' >> appopippo

Maybe this works, too:

echo $NHBPWDBATCH/PWD50*.TXT | tr ' ' '\n' >> appopippo

--
Michael Tosch @ hp : com
Cyrus Kriticos

2007-08-29, 7:26 pm

pgas wrote:
> On Aug 29, 1:45 pm, Maxwell Lol <nos...@com.invalid> wrote:
>
> This one avoids the expansion of the filenames on the "command line",
> and thus will indeed
> work with any number of files.
> Just take care that 1) it's recursive, 2) if "$NHBPWDBATCH" has a
> space it's a good idea to double quote it


find "$NHBPWDBATCH" -maxdepth 1 -name 'PWD50*.TXT' > appopippo 2>/dev/null

--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com