|
Home > Archive > Unix Shell > March 2006 > Simple tcsh question?
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 |
Simple tcsh question?
|
|
| l0o0o0b@yahoo.fr 2006-03-17, 7:50 am |
| Hi,
I am trysing to write a tcsh script which counts the number of lines
starting by @ in a file and acts differently depending on this number.
I tried:
if ( `grep ^@ "$FILE" | wc -l` > 4 ) then
echo "* No data"
# code...
else
echo "* Data OK"
# code...
endif
.... which is not doing the job.
if ( `grep ^@ "$FILE" | wc -l` > 4 ) is doing wrongly.
What should I put?
Thank you,
LoB
| |
| Bill Marcum 2006-03-17, 5:54 pm |
| On 17 Mar 2006 05:03:25 -0800, l0o0o0b@yahoo.fr
<l0o0o0b@yahoo.fr> wrote:
> Hi,
>
> I am trysing to write a tcsh script which counts the number of lines
> starting by @ in a file and acts differently depending on this number.
>
> I tried:
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) then
> echo "* No data"
> # code...
> else
> echo "* Data OK"
> # code...
> endif
>
> ... which is not doing the job.
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) is doing wrongly.
> What should I put?
>
How is it doing wrongly? Try inserting these lines before the "if":
grep ^@ "$FILE"
grep ^@ "$FILE" | wc -l
grep -c ^@ "$FILE"
--
Bizarreness is the essence of the exotic.
| |
| Chris F.A. Johnson 2006-03-17, 5:54 pm |
| On 2006-03-17, l0o0o0b@yahoo.fr wrote:
> Hi,
>
> I am trysing to write a tcsh script which counts the number of lines
> starting by @ in a file and acts differently depending on this number.
>
> I tried:
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) then
No need for wc:
if ( `grep -c ^@ "$FILE"` > 4 ) then
> echo "* No data"
> # code...
> else
> echo "* Data OK"
> # code...
> endif
>
> ... which is not doing the job.
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) is doing wrongly.
> What should I put?
What does "doing wrongly" mean[*]? What do you expect to happen?
Why do you want to say there's "No data" if the pattern is found
more than 4 times?
Apart from the fact that [t]csh is not recommended for
scripting[*], what is wrong with the script?
[**] <http://www.grymoire.com/Unix/CshTop10.txt>
<http://www.grymoire.com/Unix/Csh.html#uh-0>
<http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>
[*] When replying to a Usenet post through Google groups, please click on
"show options" at the top of the article, then click on the "Reply"
in the article headers. (see <http://cfaj.freeshell.org/google> ),
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Michael Tosch 2006-03-17, 5:54 pm |
| l0o0o0b@yahoo.fr wrote:
> Hi,
>
> I am trysing to write a tcsh script which counts the number of lines
> starting by @ in a file and acts differently depending on this number.
>
> I tried:
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) then
> echo "* No data"
> # code...
> else
> echo "* Data OK"
> # code...
> endif
>
> ... which is not doing the job.
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) is doing wrongly.
> What should I put?
>
Maybe your tcsh does special handling on ^ or @.
It is safer to quote it.
Further ensure you have defined FILE.
set FILE="myfile"
if ( `grep -c "^@" "$FILE"` > 4 ) then
Rgds
Michael
--
Michael Tosch @ hp : com
| |
| John W. Krahn 2006-03-17, 5:55 pm |
| l0o0o0b@yahoo.fr wrote:
>
> I am trysing to write a tcsh script which counts the number of lines
> starting by @ in a file and acts differently depending on this number.
>
> I tried:
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) then
> echo "* No data"
> # code...
> else
> echo "* Data OK"
> # code...
> endif
>
> ... which is not doing the job.
>
> if ( `grep ^@ "$FILE" | wc -l` > 4 ) is doing wrongly.
> What should I put?
if ( `perl -ne'?@? && ($. = 1) }{ exit !($. > 4)' "$FILE"` ) then
echo "* No data"
# code...
else
echo "* Data OK"
# code...
endif
John
--
use Perl;
program
fulfillment
|
|
|
|
|