Filenames in CSH shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filenames in CSH shell
# 1  
Old 01-27-2011
Filenames in CSH shell

Hi,

I am running into a bit of a problem. I am trying to write a script that will run an interactive (fortran) program repeatedly to dump data across 36 data channels... anyway. I have gotten this far...

Code:
#!/bin/csh
set i=0
while ($i<2)
fitsfilter $1<<EOF
$i
0
9
1
1
g
2
1250
-100
4000
9
9
e
EOF
set i=$i
@ i++
echo $i
end
cp ./$1_plots/data/$1_9hst-p*_2011-01-27*.data $HOME/Users/***/iceanalysis

What I am trying to do is to copy the data files that are being dumped from the run directory into the post processor director, see the cp command. The problem I am having is that this will copy files into the directory that I dont really want. The files have a weird naming convetion, for example:

Code:
i5r05_9hst-p00_2011-01-27_17-46-45.88.data

where p00, goes p00, p01, p02,..., p34, p35 for the individual data channels. So my question is:

1. How can get i to be presented as 00, 01, ...., 34, 35, so I can use that to define the files?

2. How do I extract the system time and date, so I can define the files better?

Thank you very much for any input.

Cheers
# 2  
Old 01-27-2011
To get date use set D=`date +%Y-%m-%d`

For you range you are probably better doing 00 to 29 in 1 lot and 30 to 35 as another:

Code:
set D=`date +%Y-%m-%d`
cp ./$1_plots/data/$1_9hst-p{[0-2]}{[0-9]}_${D}_*.data $HOME/Users/***/iceanalysis
cp ./$1_plots/data/$1_9hst-p3{[0-5]}_${D}_*.data $HOME/Users/***/iceanalysis

This User Gave Thanks to Chubler_XL For This Post:
# 3  
Old 01-28-2011
Thanks for the reply.

I am just wondering one thing. I always thought (and vaguely remembering using it that way) that you can cp a file into another directory with a different name, but when I try to say something like:

cp ./$1_plots/data/$1_9hst-p{[0-2]}{[0-9]}_${D}_*.data $HOME/Users/***/iceanalysis/$1$i.dmp

it basically tells me that I cant because *.dmp is not a folder. Am I fogetting something in my command?

---------- Post updated at 08:55 PM ---------- Previous update was at 09:44 AM ----------

I am sorry for the double post, but I am officially at a loss. I trying to copy my output files into another directory and then rename them, so I can feed them into my pyhton progam.

Anyway my code is as follows at the moment:

Code:
#!/bin/tcsh
set i=0
set fitsdir=$HOME/Runs/$1/filter
set D=`date +%Y-%m-%d`
set t=`date +%H-%M`
while ($i<12)
cd $fitsdir
fitsfilter $1$2<<EOF
$i
0
9
1
1
g
2
1250
-100
4000
9
9
e
EOF
set i=$i
@ i++
end

set j=0
while ($j<12)
    cd $fitsdir/$1$2_plots/data
    if ($j<10) then
    set p=p0$j
    cp -- $1$2_9hst-${p}_${D}_${t}*.data ~/Users/riedel/iceanalysis/$1$2hst0$j.dmp 
    else
    set p=p$j
    cp -- $1$2_9hst-${p}_${D}_${t}*.data ~/Users/riedel/iceanalysis/$1$2hst$j.dmp
    endif
    set j=$j
    @ j++
end

The C shell keeps throwing errors at me about cp and mv needing a directory as a target. I am getting more and more confused about this because I can do the command in the command line without any problem, but as soon as I try the same thing in the script it wont work at all

Any input is welcome...

Last edited by madtowneast; 01-30-2011 at 03:35 PM..
# 4  
Old 01-30-2011
When you have more than 2 files on the cp/mv command line the assumption is that you want to copy/move multiple files into a directory eg:
Code:
cp  file1 file2 file3  directory

In your case $1$2_9hst-${p}_${D}_${t}*.data is probably expanding to more than 1 file. You should also be carefull of the case were a file is not there, as something like i5r05_9hst-p07_2011-01-27_17*.data will be passed to cp as the filename and you'll get errors like:

Code:
cp: cannot stat `i5r05_9hst-p07_2011-01-27_17*.data': No such file or directory

# 5  
Old 01-30-2011
I actually tried to avoid that problem with the loop, i.e. by passing just

Code:
i5r05_9hst-p07_2011-01-27_17*.data



every time instead of a whole set. I have modified the code a little more to just rename the files after they have been copied into a specific folder, but the mv command keeps demanding a directory as the destination instead of just being able to rename the file. I tested renaming in the command line and it works fine, so I am at a loss really. I made new script just to rename the files with the same error that the destination has to be a directory.

Code:
#!/bin/tcsh
set D=`date +%Y-%m-%d`
cd $HOME/Users/riedel/iceanalysis
set i=0
while ($i<10)
if ($i<10) then
set p=p0$i
set f1=$1$2_9hst-${p}_${D}*.data
set f2=$1$2hst${p}.dmp
mv -t $f2 $f1
else
set p=p$i
mv $1$2_9hst-${p}_${D}*.data $1$2hst${p}.dmp
endif
set i=$i
@ i++
end


# 6  
Old 01-30-2011
Try replacing the mv commands with echo so you can see what args are being passed to cp.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell program question with Filenames and dates

Hi Unix Gurus Let's say I have the input files like the following. I need to pick the files based on my run date. abcd_20180206.csv abcd_20180213.csv abcd_20180220.csv abcd_20180227.csv efgh_20180206.csv efgh_20180220.csv efgh_20180227.csv ijkl_20180206.csv ijkl_20180213.csv... (9 Replies)
Discussion started by: SK123
9 Replies

2. Shell Programming and Scripting

String operation in csh shell

Hi, to everybody i have a string which Looks like this FT47;3;1;1;;;1;09.02.2017 21:21:19;2;2 and i would like to change to value on one Position only e.g. the values on Position 6 should change to 1 nevertheyless which values was there before AIX 4.3.2.0 and csh i try... (10 Replies)
Discussion started by: Nadielosabra
10 Replies

3. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

4. Shell Programming and Scripting

Storing filenames in an array in shell script

hi, i am writing a shell script in which i read a line in a variable. FNAME="s1.txt s2.txt s3.txt s4.txt s5.txt" i want to create a array and store single file names in a array.. so the array should contain arr="s1.txt" arr="s2.txt" arr="s3.txt" arr="s4.txt" arr="s5.txt" how to... (3 Replies)
Discussion started by: Little
3 Replies

5. Shell Programming and Scripting

Regarding c-shell (csh) scripting

Hi, I'm reading a csh setup script, and came across these lines: ################################ if (! $?PROJECT_ROOT) then setenv PROJECT_ROOT /proj/proj_123 endif ################################ Does the if endif command means, "if there is no variable named "PROJECT_ROOT",... (3 Replies)
Discussion started by: mar85
3 Replies

6. Shell Programming and Scripting

Spaces in filenames located in variables in shell.

Greetings. I am trying to do a script that will do some file copying for me. Unfortunately I have spaces in the directory names (which I cannot change) and the result is someone hard to achieve in shell scripts. I have searched everywhere on the web but does not manage to find the answer to... (3 Replies)
Discussion started by: Mr.Glaurung
3 Replies

7. Shell Programming and Scripting

how to shift few words of filenames at a time using shell script

Hello everybody, I have some files in directory. I want to shift 3 characters of filenames to the right at a same time. for example, I have filenames like $ls -l 01_2000.G3.input.txt 02_2000.G3.input.txt ..., ..., 04_2010.G3.input.txt I want to change the filenames like... (3 Replies)
Discussion started by: yogeshkumkar
3 Replies

8. Shell Programming and Scripting

How to list filenames with spaces in shell script

Hi, I want to list all the files matching in a directory directory given below Here one of the folder has a space in the path. /MAS02/RMS/WBDev/Krishna/Krishna Mohan/FMSplitByKeyAfterChanges1000075383.fileman.*.txt.out.1000075383.0 The following works from command line... (1 Reply)
Discussion started by: hikrishn
1 Replies

9. Shell Programming and Scripting

different shell csh bash

I'm always having to work in the cshell, but occasionally want to run a command using bash. is that possible? I know I could write a shell script and call bash at the begining with #!/usr/bin/bash and then my command, is there another way? (1 Reply)
Discussion started by: ajp7701
1 Replies

10. UNIX for Dummies Questions & Answers

Options for csh shell

Hello, It's possible to change/put some options of the C-shell, like bold-text, date, etc? I can't found a web site that have a explanation. Thanks. (10 Replies)
Discussion started by: luiz_fer10
10 Replies
Login or Register to Ask a Question