|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
a command like
ls $NHBPWDBATCH/PWD50*.TXT >> appopippo 2>/dev/null does not work when there are many files How can i substitute it ? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 you to: set -o xtrace After you have set this option every command is displayed how the shell interpretes it... |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Aug 29, 1:45 pm, Maxwell Lol <nos...@com.invalid> wrote:
> pincopallo...@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 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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Bill Marcum wrote:
> 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 > 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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
pgas wrote:
> On Aug 29, 1:45 pm, Maxwell Lol <nos...@com.invalid> wrote: >> pincopallo...@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 ? >> >> 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 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 |
|
![]() |
| Outils de la discussion | |
|
|