csh desperate help...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting csh desperate help...
# 1  
Old 12-05-2011
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:

Code:
#!/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.

Last edited by fpmurphy; 12-05-2011 at 10:59 AM.. Reason: Code tags please!
# 2  
Old 12-05-2011
How about:
Code:
ls -1 | grep -v '^my_file$' | myprogram

# 3  
Old 12-05-2011
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
# 4  
Old 12-05-2011
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
# 5  
Old 12-05-2011
Close to...but grep -v is not working

Code:
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------------------------------------------------------------------------------
Code:
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 ----------
Code:
set list=`ls *.hed`


Last edited by Scott; 12-05-2011 at 01:59 PM.. Reason: Please use code tags
# 6  
Old 12-05-2011
try this Smilie
Code:
# ./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

Code:
# 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
This User Gave Thanks to ygemici For This Post:
# 7  
Old 12-06-2011
Not sure if this is what you are looking for Smilie

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

This User Gave Thanks to theflamingmoe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UUCP HELP for a desperate new user

Hello, I have a unique situation where I must pass along critical & time-sensitive emails to a group of seven different people. Every person with whom I communicate EXCEPT ONE uses a standard IP based ".com" email address. The one exception is a gentleman who will NOT budge and create a... (1 Reply)
Discussion started by: Bell02
1 Replies

2. SCO

Desperate for SCO OpenServer 5.0.6 ISO

Is anyone able to help. Desperately trying to virtualise an ageing Pecase system on SCO 5.0.6 (2 Replies)
Discussion started by: ElGato
2 Replies

3. SCO

Desperate for SCO OpenServer 5.0.6Is

Is anyone able to help. Desperately trying to virtualise an ageing Pecase system on SCO 5.0.6 (1 Reply)
Discussion started by: ElGato
1 Replies

4. Shell Programming and Scripting

Desperate for help with menu coding

I am extremely desperate for help with this menu coding problem I'm having. Whenver I go to execute my script file, I keep getting an error message that says the following: option: Undefined variable. I implore someone to PUH-LEEZE point me in the right direction. I can't stress my... (21 Replies)
Discussion started by: sinjin
21 Replies

5. UNIX for Dummies Questions & Answers

Please help me decipher this header - I'm desperate!

I've got a really weird situation here.... the same IP address keeps popping up in porn spam that I have rec'd in 2 different email accts. It looks to me like it's coming from UC Davis, and I suspect someone there, so I am hoping you all can verify the same thing before I call the person on this... (0 Replies)
Discussion started by: christinef
0 Replies

6. Shell Programming and Scripting

perl odbc... need desperate help!

Hey guys: Can anyone show me , how I can update mulitple fields in a database (sample Informix) using Win32::ODBC ? I'm creating a script that accepts an array as the value and then inserts these values into all the table fields in a particular database... Thanks for anyone who can... (2 Replies)
Discussion started by: jfsuminist
2 Replies

7. UNIX for Advanced & Expert Users

Please Help.... Desperate need! Hard Question!

I know pipelined processors have issues with interupts.... but why? And does the architecture of the CPU affect the kind of software that can run on it? If someone could help me out that would be awsome. My boss came to me with this question and I can't find anything on the web helping me out.... (1 Reply)
Discussion started by: Sparticus007
1 Replies

8. UNIX for Dummies Questions & Answers

I am confused and desperate

Hello, For a time now I have this problem which I cannot solve and this bothers me cause it seems so simple. I have to change an existing (ftp only)user to create a timeslot for this user. (e.g. he can only login between 8 and 10 PM). Facts: - I can only use a terminal client (no gui) -... (1 Reply)
Discussion started by: derk
1 Replies
Login or Register to Ask a Question