Running program and output files in specific directories
I have been running a program mseed2sac using the following command
Code:
cd IV
find . -type f -exec /swadmin/mseed2sac '{}' \;
The problem is that I end up with a lot of files in directory IV.
Instead I would like to select the designator HHZ, create a
directory IV.SAC and all the files output for mseed2sac
get stored there
The two directories IV and IV.SAC would be at the same level
I am using Trisquel and writing a script in bash. I do not want to modify the program mseed2sac as I think it would be too much work and so arrange the file structure in a bash script.
For example when I do
Code:
mseed2sac favr/hhz.d/iv.favr..hhz.d.2016.226
Wrote 8639767 samples to IV.FAVR..HHZ.D.2016.226.000003.SAC
I get the file IV.FAVR..HHZ.D.2016.226.000003.SAC at the location where I have run the program
mseed2sac.
Code:
/home/hagbard/swadmin/mseed2sac/mseed2sac -H
mseed2sac version: 2.2
Convert miniSEED data to SAC
Usage: mseed2sac [options] input1.mseed [input2.mseed ...]
## Options ##
-V Report program version
-h Show this usage message
-H Print an extended usage message
-v Be more verbose, multiple flags can be used
-O Overwrite existing output files, default creates new file names
-k lat/lon Specify station coordinates as 'Latitude/Longitude' in degrees
-m metafile File containing channel metadata (coordinates and more)
-M metaline Channel metadata, same format as lines in metafile
-msi Convert component inclination/dip from SEED to SAC convention
-E event Specify event parameters as 'Time[/Lat][/Lon][/Depth][/Name]'
e.g. '2006,123,15:27:08.7/-20.33/-174.03/65.5/Tonga'
-l selectfile Read a list of selections from file, used for subsetting
-f format Specify SAC file format (default is 2:binary):
1=alpha, 2=binary (host byte order),
3=binary (little-endian), 4=binary (big-endian)
More options are available, to see their description use the -H option
-N network Specify the network code, overrides any value in the SEED
-S station Specify the station code, overrides any value in the SEED
-L location Specify the location code, overrides any value in the SEED
-C channel Specify the channel code, overrides any value in the SEED
-r bytes Specify SEED record length in bytes, autodetected by default
-i Process each input file individually instead of merged
-ic Process each channel individually, data should be well ordered
-dr Use the sampling rate derived from the time stamps instead
of the sample rate denoted in the input data
-z zipfile Write all SAC files to a ZIP archive, use '-' for stdout
-z0 zipfile Same as -z but do not compress archive entries
---------- Post updated at 09:18 AM ---------- Previous update was at 05:23 AM ----------
Have been trying to create a strong with the new directory name
using rename but it is not working very well.
We would have loved to have been able to help you, but with the information you provided, we weren't able to do much. I asked for the man page your mseed2sec. Instead of that you supplied us with a help message from that utility. Unfortunately, the help message says absolutely nothing about what the purpose of the utility is, what it will do with the input files, what, if any, output files it will produce, ...
And, then you told us that you wanted to invoke it using the format:
Code:
mseed2sac file1 file2 file2
which seemed very strange since there is no indication that feeding one file (file2 in this case) to the utility twice in one invocation would serve any useful purpose. But, you did later change this line to again just pass one pathname to your utility (without explaining why you made that change).
You pass it a list of files in seed format (Standard for the Exchange of Earthquake Data)
and outputs a set of files in sac format (a format used by the Seismic Analysis Code SAC).
For example, running mseed2sac as follows
mseed2sac iv/cagr/hhz.d/iv.cagr..hhz.d.2016.208
The program then creates a number of files (in the directory where mseed2sac is run)
as shown in the list below. I want then to move to a new directory, for example to
`iv.sac/cagr/hhz.d/`
.d means day. So for 2016.208 means file for day 208.
---------- Post updated at 01:07 PM ---------- Previous update was at 11:26 AM ----------
Now I have updated the code as follows which transfer the generated files
to the correct directory. Any improvements or possible problems with my
code would be very welcome.
Code:
# Counts the number of files to process
totfcn=$(find . -type f | tee /tmp/wrk | wc -l)
i=0; j=0
while read fn; do
printf -v XXX "%0*d" $((60 * ++i / totfcn))
printf "\r[%-60s]" "${XXX//0/*}"
printf "%4d%%" $((100 * ++j / totfcn))
#${dir_mseed2sac}/mseed2sac $fn
done < /tmp/wrk
printf "\n"
while read fn; do
#${dir_mseed2sac}/mseed2sac $fn
dir=$(dirname "$fn") # Gets directory path
fnm=$(basename "$fn") # Gets filename excl. path
rgx_nwk="s/${nwk}/${nwk}.sac/g"
odir_nwk=`echo "$dir" | sed -e $rgx_nwk`
ofl_nwk="${odir_nwk}/${fnm}"
echo "fn: $fn"
if [ -d "$odir_nwk" ]; then
echo "Directory already exists: $odir_nwk"
else
echo "+ dir: $dir"
echo "+ fnm: $fnm"
echo "+ mkdir -p $odir_nwk"
fi
echo "+ mv ${fnm}.* ${odir_nwk}/"
done < /tmp/wrk
Hello,
I'm a first time poster looking for help in scripting a task in my daily routine. I am new in unix but i am attracted to its use as a mac user.
Bear with me...
I have several files (20) that I manually drag via the mouse into several named directories over a network. I've used rsync... (14 Replies)
hi,
i have a requirement to delete all the files from all the directories except some specific directories like archive and log.
for example:
there are following directories such as
A B C D Archive E Log F
which contains some sub directories and files. The requirement is to delete all the... (7 Replies)
Hi everyone
My issue is this, I need to list all the sub directories in a directory that contains files that have the extension *.log, *.dat and *.out . After reviewing the output i need to delete those directories i do not need. I am running Solaris 10 in a bash shell. I have a script that I... (2 Replies)
Hi,
I have to find specific files only in the current directory...not in the sub directories.
But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..
I am using the below command. And i am... (2 Replies)
Hi Guys,
What I am looking at doing is to run a C program in my home directory, but output files in multiple directories BUT not at the same instance.
For e.g.
1st instance:
Run program.c and output results in path /aaa/bbb/ccc/
2nd instance:
Run program.c again and output results... (9 Replies)
I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find )
The directory structure looks like :-
/tmp
a.log
b.log
c.log
/abcd
d.log
e.log
When I tried the following command , it movies all the log files... (8 Replies)
I have searched about 30 threads, a load of Google pages and cannot find what I am looking for. I have some of the parts but not the whole. I cannot seem to get the puzzle fit together.
I have three folders, two of which contain different versions of multiple files, dist/file1.php dist/file2.php... (4 Replies)
Hello, this is probably another really simple tasks for most of you gurus, however I am trying to make a script which takes an input, greps a specific file for that input, prints back to screen the results (which are directory names) and then be able to use the directory names to move files.... (1 Reply)
Hello,
I would like to list the files from all directories that has been modified more than 1 month ago, and whose name is like '*risk*log'.
I think a script like this should work :
ls -R | find -name '*risk*.log' -mtime 30 -type f
But it tells me "no file found" though I can see some.
... (4 Replies)