views:

44

answers:

1

I'm workin on C-Shell, can somebody help me find the bug, my 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 one number

038280083

I thought cut must cut 2 field from all rows... thanks in advance for any help I expect to see second field from all rows from 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
+1  A: 

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
Amir Rachum
You tried to do, what I did? You have the same result?
lego69
I did the same thing as You, it can't give me even first row:(
lego69
@lego69 what output did it give you? did it end or not? did it give an error?
Amir Rachum
no, it gave prompt, I use windows for writing scripts and after run it on unix server, with usin dos2unix, may it cause the problem?
lego69
Could be, please post the content of the file AFTER `dos2unix`.
Amir Rachum
I did it with echo, no effect, the same problem
lego69
@lego69 both ways worked for me, this causes me to think that something other than the script is wrong at your side. Please post the contents of the scripts after `dos2unix` (do `cat rank` and post the output).
Amir Rachum
I posted it in my question
lego69
@lego69 Ok, remove all those `$` signs from the line ends in the script! You can use `pico` for example.
Amir Rachum
ok, how can I delete this $ in pico, it didn't show me it
lego69
@lego69 Dude, this is some basic unix operations you should really know how to do. pico is just like notepad. run `pico rank`, use the arrows to go to the dollar signs and delete them. then hit Ctrl-X, click `y`, then press enter.
Amir Rachum
ok, thanks a lot for you help
lego69