csh desperate help...

Hi guys,

I am really newbie of csh and I am stuck with a script.

Basically what I want to do is assign to a variable (array) the output of "ls". Then look at this array and if there is the word "my_file", delete it from the array and echo the new array.

Moreover, I would like to have that every single item of my array is the input of a program.

Well I am stuck with both things. This is what I thought:

#!/bin/csh

set list=`ls *.img`

echo  -n "Name of your final dataset:"

set y = $myfile (the item that I want to remove from the array)

foreach i ($list)
if ($i =~ $y) then		
unset ${list[$i]}	
echo $list
/my_program <<EOF
$i
data
EOF

endif

I don't know how to find the index of an item in the list and delete exactly that item.

Please help...

Thanks guys.

How about:

ls -1 | grep -v '^my_file$' | myprogram

Hi m.d.ludwig,

thanks, but what do you mean with that. grep -v invert the selection, doesn't it? I don't think it is gonna help, although i tried your suggestion.

Perhaps, I am using it in a wrong way.

Any other suggestion?

Cheers

If it was any shell but csh I'd have an idea but csh has extremely limited features and won't work with any of my ideas.

csh programming considered harmful

echo  -n "Name of your final dataset:"
set my_dataset=$<
set A=`grep -vl $my_dataset $list`

echo "Appending:" $A
echo "Number of file:" $#A

foreach i ($A)
/append.e <<EOF
$i
$my_dataset
EOF
end

/headers.e <<EOF
HY
$my_dataset
EOF

output------------------------------------------------------------------------------

Name of your final dataset:dataset
Appending: dataset.hed d.hed mcm169_box300.hed mcm170_box300.hed
Number of file: 4

if I type 'data' grep exclude dataset from the list if I type 'dataset' grep doesn't exclude it from the list
I tried different options but no way.

---------- Post updated at 05:31 PM ---------- Previous update was at 05:30 PM ----------

set list=`ls *.hed`

try this :wink:

# ./justdoit_cs1
LIST  -> a.img b.img c.img d.img e.img
Name of your final dataset: c.img
NEW LIST  -> a.img b.img d.img e.img
# cat justdoit_cs1
#!/bin/csh
set list=`ls *.img`
echo LIST " -> $list"
echo -n "Name of your final dataset: "
set y = $<
set x = 0
foreach i ($list)
@ x++
if ("$i" == "$y") then
set list[$x] =
set list = `echo $list`
endif
end
echo NEW LIST "$list"

regards
ygemici

1 Like

Not sure if this is what you are looking for :o

 
set y = $<
foreach i (`ls *.img`)
  if ("$i" != "$y") then
  echo $i >> newlist.txt
end
set newlist = `cat newlist.txt`
1 Like
 
set y = $<
echo >newlist.txt
foreach i (`ls *.img`)
  if ("$i" != "$y") then
  echo $i >> newlist.txt
endif
end
set newlist = `cat newlist.txt`

ygemici ...it is just spot on! It works fine.

Thanks guys for you help..

Giuseppe