Computing.Net > Forums > Unix > std error line count

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

std error line count

Reply to Message Icon

Name: PaulDavidSumner
Date: April 20, 2006 at 04:31:33 Pacific
OS: Windows XP Build 2600
CPU/Ram: Pentium 4 2.26 GHz/256 MB
Product: Dell GX260 Optiplex
Comment:

I want to assign a variable to the number of files NOT found by an ls command.
Suppose we have the following variables:

DIRECTORY=/vw/dev/icwdev/opins
FILE_LIST='UVW1000 UVW1002 UVW1004 UVW1006 UVW1008 UVW1009 UVW1010 UVWXXXX'

In this example, all the files in $FILE_LIST exist in $DIRECTORY, except UVWXXXX.

I can assign a variable to the number of files which exist in the directory using:

NO_OF_EXISTING_FILES=`ls -1 $FILE_LIST | wc -l`

I want to have a variable which is the opposite - the number of files which don't exist in the directory. I tried the following...

NO_OF_MISSING_FILES=`ls -1 $FILE_LIST | wc -l >/dev/null`

...on the hope that the real file listing would be 'thrown away', but the lines reading 'No such file or directory', having not been thrown away, would be picked up by wc -l. However, the wc -l command is not picking up input from standard error, which, I suppose, I should have expected.

How do I get wc -l to count the number of standard error lines from a command that's piped into it?



Sponsored Link
Ads by Google

Response Number 1
Name: PaulDavidSumner
Date: April 20, 2006 at 04:33:16 Pacific
Reply:

Korn Shell.
Solaris server.


0

Response Number 2
Name: nails
Date: April 20, 2006 at 11:07:19 Pacific
Reply:


NO_OF_MISSING_FILES=`ls -l $FILE_LIST 2> /dev/null |wc -l`
echo $NO_OF_MISSING_FILES


0

Response Number 3
Name: nails
Date: April 20, 2006 at 11:13:21 Pacific
Reply:

Sorry, I misread your question. At least, the above throws away the 'file not found' error. I'll think about this, and if I come up with a better answer, I'll let you know.


0

Response Number 4
Name: lchi2000g
Date: April 20, 2006 at 11:21:29 Pacific
Reply:

replace:

NO_OF_EXISTING_FILES=`ls -1 $FILE_LIST | wc -l`


with:

NO_OF_EXISTING_FILES=`ls -1 $FILE_LIST 2> /dev/null | wc -l`


Luke Chi


0

Response Number 5
Name: lchi2000g
Date: April 20, 2006 at 11:43:28 Pacific
Reply:

I misunderstood it too. Here is the right answer.

#!/bin/sh <====== borne shell
NO_OF_MISSING_FILES=`ls -1 $FILE_LIST 3>&2 2>&1 1>&3 | wc -l`

Luke Chi


0

Related Posts

See More



Response Number 6
Name: lchi2000g
Date: April 20, 2006 at 12:21:13 Pacific
Reply:

sorry. i forgot to get rid of standard output:

NO_OF_MISSING_FILES=`ls -1 $FILE_LIST 3>&2 2>&1 1>&3 > /dev/null | wc -l`


Luke Chi


0

Response Number 7
Name: PaulDavidSumner
Date: April 26, 2006 at 07:29:47 Pacific
Reply:

Thanks, that's a good solution.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Modifying contents of fil... days left in current mont...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: std error line count

find command skipp std error & exec www.computing.net/answers/unix/find-command-skipp-std-error-amp-exec/7960.html

How to join two text lines on one l www.computing.net/answers/unix/how-to-join-two-text-lines-on-one-l/7100.html

Using while loop to read a file www.computing.net/answers/unix/using-while-loop-to-read-a-file/7092.html