Hello,
I have a question regarding file naming under a loop in tcsh. I have the following code:
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:
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
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Don't know about tcsh but maybe this example can help a little :
Just feel free to test and adapt to your needs.
parsing 4 could also be written ${line%/*} (but i don't know whether tcsh handle it or not)
By the way, if you want to use sed in order to parse Path name that contains / you'd better go for a delimiter such as | or : instead of a / otherwise you would have to escape any / by a \ otherwise would be interpreted as a delimiter ...
2) ls will normally list in AN order, so to get them numerically sorted and grab a range:
Narrative:
List the directory (will come out one file per line when to a pipe).
Have sed find the only number part at the end and copy it to the front with a space.
Sort the stream in forward numeric order.
Have sed preserve the lines in the range, the remove the number and space prefix.
You can put this on a command line with `command string` or use 'xargs -n 19 your_cmd' to build and execute command lines of 1 to 19 file args. As I recall, xargs is a little squirrelly if you do not use -n, executing with no arguments. If you just want to do n at a time in any order, xargs -n will do that.
As xargs has been know to provide quoting challenges with funny things like file names (lines) with metachar or white space in them (it coposes an actual command line, I wrote fxargs and then fxargs2 to take lines directly to null terminated strings in an argv[] to pass to exec() without a command line. It saves a few cycles, too. The second one is smarter about building a command line of any # of args as input arrives while waiting for the last command execution to complete, so less time is lost, less latency. The first command might have 3 args, the next 6, and so on as input arrives.
I love modular tools. These each bridge a gap, like `` ksh $() and xargs go from stream/stdin to command line, echo goes from command line to stream/stdout. The beauty of xargs is that it scales up no limit. I write a lot of tools that take args on stdin as lines, not on the command line, so they are interchangable pipe fittings. I am a power user, I guess!
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)
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)
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)
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)
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)
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)
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)
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)
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)