lego69
lego69

Reputation: 857

Why do I get only one number from this script?

What is the bug in the following script?

#! /bin/tcsh -f
cut -d" " -f2 ${1} | ./rankHelper

Script rankHelper:

#! /bin/tcsh -f
set line = ($<)
while(${#line} != 0)
cat $line
set line = ($<)
end

File lines from which the data was sent:

053-3787837 038280083
052-3436363 012345678 
053-3232287 038280083 
054-3923898 033333333 
052-2222333 012345678 
052-1111111 012390387 

I run it using:

> ./rank lines

Why do I receive only the following one number?

038280083

I thought cut must cut two fields from all rows. I expect to see the second field from all rows from the lines:

dos2unix: converting file rank to UNIX format ...
 > ./rank lines
 > 

 > cat -A rank
#! /bin/tcsh -f$
cut -d" " -f2 ${1} | ./rankHelper


> cat -A rankHelper
#! /bin/tcsh -f$
set line = ($<)$
$
$
while(${#line} != 0)$
$
echo $line$
set line = ($<)$
end

I'm working on C shell.

Upvotes: 0

Views: 87

Answers (1)

Amir Rachum
Amir Rachum

Reputation: 79685

I changed rank to this:

#! /bin/tcsh -f
cut -d" " -f2 ${1}

and ran

> ./rank lines

and it worked for me.

Edit: If you still want to use rankHelper for some reason (homework?), try changing, in rankHelper the command

cat $line

to

echo $line

Upvotes: 1

Related Questions