csh script to search for files and display result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting csh script to search for files and display result
# 1  
Old 10-06-2008
Question csh script to search for files and display result

Hello all. I'm a long time browser, first time poster...Be gentle :-)

I don't use csh much, but have been asked to make a small script for our HP-UX systems to search for a report file(s) or summary file and display the result (I was using vuepad, but this probably is just
complicating things)

My latest error is <if: expression> after if ($type =="R".... I can't see what's wrong.. Can anyone help..?

Here's the code.

#!/usr/bin/csh
set sumdir = ( /users/probe/buffer/summary/ )
set reportdir = ( /users/probe/buffer/reports/)
printf "\n enter lot number, lower case, \n E.G. p260091p1 \n"
set lot = $<
printf "\n Report or Summary \n (R or S) \n ? "
set type = $<
if ( $type == "R" ) then
type ="r"
set files = ( `ls $reportdir | grep $lot ` )
endif
if ( $type =="S" ) then
$type ="s"
set files = ( `ls $sumdir | grep $lot ` )
else
printf "\n Type only R or S \n "
endif


set z = 1
printf "\nWHich file do you want to view?\n\n"
while ($z <= $#files)
printf "\tFILE %2d = %s\n" $z $files[$z]
set z = $z + 1
end
set last = $z - 1
printf "\nSelect (0-$last):"
set choice = ($<)
if ( $choice < 0 || $choice > $last ) then
printf "No Such File.\n"
goto END
endif
if ( $choice > 0 ) then
set FILE = ( $files[$choice] )
else
set FILE = ( $files )
endif
foreach oneFILE ( $FILE )

if $file ="r" then

/usr/vue/bin/vuepad $reportdir$oneFILE
else
/usr/vue/bin/vuepad $sumdir$oneFILE
endif
end
END:
#EOF
# 2  
Old 10-06-2008
Are you sure you get the error at the if ( $test == "R" ) ??

When I ran your script, I got the same error at the == "S" part. There you seem to need a space between == and "S".
# 3  
Old 10-06-2008
Why couldn't I see that..? I am just careless after writing so much code in langages that just don't care about these things..

My next sticky point is

while ($z <= $#files)
printf "\tFILE %2d = %s\n" $z $files[$z]

set z = $z + 1
end

Is the syntax for <while> ok? When executed I get ... files: Undefined Variable.
# 4  
Old 10-06-2008
I don't know anything about arrays in csh.
# 5  
Old 03-08-2009
Do you still need help with this?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search string in multiple files and display column wise

I have 3 files. Each of those files have the same number of records, however certain records have different values. I would like to grep the field in ALL 3 files and display the output with only the differences in column wise and if possible line number File1 Name = Joe Age = 33... (3 Replies)
Discussion started by: sidnow
3 Replies

2. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

3. Shell Programming and Scripting

Different epoch conversion result for bash and csh users

Hi there I'm using this script to convert command line history with Epoch time stamp to human readable. While it works fine with users with /bin/csh shell, it fails to convert for users with /bin/bash shell. Why is this happening? I even changed and added * and after the # but it still didnt... (2 Replies)
Discussion started by: hedkandi
2 Replies

4. Shell Programming and Scripting

Bash script to display result in table

My script gives the following result. Is it possible to display the same in table format ? 1. rex_best Latest feeds are not avaialable. The last feed was generated on 2012-05-17 File Name = ekb_best_20120517_010949_665.tar.gz The Number of entry elements = 4209539 2. rex_genre Latest... (2 Replies)
Discussion started by: kishorekumar87
2 Replies

5. Shell Programming and Scripting

Delete files using csh script

Want to write a csh scripts where I pass the extension of certain files, and the script will detete all such files. For example, the following will delete all files with extension .xt ./clean.csh xt (6 Replies)
Discussion started by: kristinu
6 Replies

6. Shell Programming and Scripting

In a csh script, can I set a variable to the result of an SQLPLUS select query?

Can someone tell me why I'm getting error when I try to run this? #!/bin/csh -f source ~/.cshrc # set SQLPLUS = ${ORACLE_HOME}/bin/sqlplus # set count=`$SQLPLUS -s ${DB_LOGIN} << END select count(1) from put_groups where group_name='PC' and description='EOD_EVENT' and serial_number=1;... (7 Replies)
Discussion started by: gregrobinsonhd
7 Replies

7. Shell Programming and Scripting

Sending/append result from CSH script to xls file

Hi, 1st post... Done a quick search for this so apologies if I've missed it. Basically I want to output and and append several values generated by a csh script direct to an xls openoffice file, rather than send to txt file and then physically copy and paste to xls file. Already I send... (4 Replies)
Discussion started by: scottyjock
4 Replies

8. UNIX for Dummies Questions & Answers

Perl search and replace not working in csh script

I am using perl to perform a search and replace. It works at the command line, but not in the csh shell script perl -pi -e 's@/Pattern@@g' $path/$file I used the @ as my delimiter because the pattern contains "/" (3 Replies)
Discussion started by: NobluesFDT
3 Replies

9. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

10. UNIX for Dummies Questions & Answers

display the result of wc -l with words before and after the result

hello showrev -p | wc -l returns: 381 What to do in case I want to have this output: number of lines returned by showrev -p is: 381 thx (3 Replies)
Discussion started by: melanie_pfefer
3 Replies
Login or Register to Ask a Question