Sponsored Content
Top Forums Shell Programming and Scripting Problem with File Names under tcsh loop Post 302465452 by InfoSeeker on Friday 22nd of October 2010 12:28:37 PM
Old 10-22-2010
Question Problem with File Names under tcsh loop

Hello,
I have a question regarding file naming under a loop in tcsh. I have the following code:
Code:
#!/bin/tcsh
foreach file (test/ProteinDirectory/*)   # The * is a bunch of ProteinFile1, ProteinFile2, ProteinFile3, etc.
sh /bioinfo/home/dgendoo/THREADER/pGenThreader.sh $file $file 
         #the first $file is really supposed to represent the filename, the second $file is the actual path!
echo DONE! $file#protein name is what I'm aiming for
end

The problem:
If I echo $file in the loop, it will print the entire path: test/ProteinDirectory/ProteinFile1
I want a way to only extract the actual file name (ex: ProteinFile1) to use in the loop to rename my files, and still retain the $file because I need that path as input.
So in that case the code would be something like:

Code:
#!/bin/tcsh
foreach file (test/ProteinDirectory/*)
set ProteinName = ?? 
           # Where ProteinName = ProteinFile1, ProteinFile2, etc. Probably some string manipulation on $file
sh /bioinfo/home/dgendoo/THREADER/pGenThreader.sh ProteinName $file
echo DONE! ProteinName
end

1. Could you suggest a way to do this? I think it could be done in Sed with a / delimiter, but I am not very familiar with that language.

2. I also wanted to try and modify this loop so that I only work on 200 ProteinFiles at one time, so I wanted some sort of condition to say "execute from ProteinFile5 to ProteinFile205". I would really appreciate some input on how to incorporate this condition into the loop also.

Thank you very much for your help!

Last edited by vbe; 10-22-2010 at 01:48 PM.. Reason: Code tags please
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

TCSH.need help.take input during a while/end loop

I am writting a script in csh and I am blanking out on how I code in the ability to process user input in the middle of a while/end loop. while(1) args.. end it is a simple script, and I want to add hotkey functions, like q to quit, z to zero counters, etc.. Google has not been very... (1 Reply)
Discussion started by: seg
1 Replies

2. UNIX for Dummies Questions & Answers

Top level TCSH while Loop doen't work

Hey guys... I'm learning some shell scripting on OS X using the tcsh shell. For some reason... my while loop isn't executing right (or more likely I am doing something wrong.) Something as simple as this doesn't work: #!/bin/tcsh set g = 0 while ($g <10) echo "this" $g @ g =... (2 Replies)
Discussion started by: sprynmr
2 Replies

3. Shell Programming and Scripting

File Names in a Variable in a loop

Hi All , I am having confusion in a shell script. Please guide me. I need to get multiple files (number of files vary time to time, file names are separated by '|') using FTP get from the remote server. Actually, i call the FTP function in a loop. At the last step, i need to move all the get... (3 Replies)
Discussion started by: spkandy
3 Replies

4. Shell Programming and Scripting

Help with gawk array, loop in tcsh script

Hi, I'm trying to break a large csv file into smaller files and use unique values for the file names. The shell script i'm using is tcsh and i'm after a gawk one-liner to get the desired outcome. To keep things simple I have the following example with the desired output. fruitlist.csv apples... (6 Replies)
Discussion started by: theflamingmoe
6 Replies

5. Shell Programming and Scripting

TCSH scripts that use the same variable names

If I run two different TCSH scripts simultaneously that use identical variable names will this cause any problems? (1 Reply)
Discussion started by: thibodc
1 Replies

6. Shell Programming and Scripting

Print file names in a loop

OS : RHEL 6.1 Shell : Bash I have lots of files in /tmp/stage directory as show below. Using a loop, I need to print all the filenames in this directory except those ending with a number. How can I do this ? # pwd /tmp/stage # # # ls -l * -rw-r--r--. 1 root root 0 Oct 7 18:38 stmt1... (2 Replies)
Discussion started by: kraljic
2 Replies

7. UNIX for Dummies Questions & Answers

How to remove first few characters from multiple file names without do loop?

Hi Fellows, I was wondering how I can remove first few characters from multiple file names without do loop in unix? e.g. water123.xyz water456.xyz to 123.xyz 456.xyz Thanks Paul Thanks. (3 Replies)
Discussion started by: Paul Moghadam
3 Replies

8. Shell Programming and Scripting

Using nested for loop to iterate over file names

I'm trying to grab a list of file names from a directory, then process those files 5 at a time. In the link below. Instead of using files I'm using the files array which contains 15 strings starting with AAA. So I'm trying to assign $fileset 5 of the strings at a time to pass to a command. So... (4 Replies)
Discussion started by: zBernie
4 Replies

9. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

10. Programming

FORTRAN: Loop over variable file names

Hi guys I'm a beginner in fortran. So excuse me for my naivety, let me briefly describe what I was trying to do. I have let's say 2 files named reac-1 and reac-2. After opening these files I've to do some calculations, close these files and open the same files again in a loop. So my faulty code... (6 Replies)
Discussion started by: saleheen
6 Replies
shells(4)							   File Formats 							 shells(4)

NAME
shells - shell database SYNOPSIS
/etc/shells DESCRIPTION
The shells file contains a list of the shells on the system. Applications use this file to determine whether a shell is valid. See getuser- shell(3C). For each shell a single line should be present, consisting of the shell's path, relative to root. A hash mark (#) indicates the beginning of a comment; subsequent characters up to the end of the line are not interpreted by the routines which search the file. Blank lines are also ignored. The following default shells are used by utilities: /bin/bash, /bin/csh, /bin/jsh, /bin/ksh, /bin/pfcsh, /bin/pfksh, /bin/pfsh, /bin/sh, /bin/tcsh, /bin/zsh, /sbin/jsh, /sbin/sh, /usr/bin/bash, /usr/bin/csh, /usr/bin/jsh, /usr/bin/ksh, /usr/bin/pfcsh, /usr/bin/pfksh, /usr/bin/pfsh, and /usr/bin/sh, /usr/bin/tcsh, /usr/bin/zsh. Note that /etc/shells overrides the default list. Invalid shells in /etc/shells may cause unexpected behavior (such as being unable to log in by way of ftp(1)). FILES
/etc/shells lists shells on system SEE ALSO
vipw(1B), ftpd(1M), sendmail(1M), getusershell(3C), aliases(4) SunOS 5.10 4 Jun 2001 shells(4)
All times are GMT -4. The time now is 06:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy