Sponsored Content
Top Forums Shell Programming and Scripting Running program and output files in specific directories Post 303013238 by kristinu on Sunday 18th of February 2018 01:07:54 PM
Old 02-18-2018
Seed Format

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.

Code:
iv.cagr..hhz.d.2016.208.000001.sac  iv.cagr..hhz.d.2016.208.043041.sac  iv.cagr..hhz.d.2016.208.070027.sac  iv.cagr..hhz.d.2016.208.121238.sac
iv.cagr..hhz.d.2016.208.131218.sac  iv.cagr..hhz.d.2016.208.132855.sac  iv.cagr..hhz.d.2016.208.132938.sac  iv.cagr..hhz.d.2016.208.133025.sac
iv.cagr..hhz.d.2016.208.133143.sac  iv.cagr..hhz.d.2016.208.133225.sac  iv.cagr..hhz.d.2016.208.133324.sac  iv.cagr..hhz.d.2016.208.133329.sac
iv.cagr..hhz.d.2016.208.133416.sac  iv.cagr..hhz.d.2016.208.133444.sac  iv.cagr..hhz.d.2016.208.133516.sac  iv.cagr..hhz.d.2016.208.133554.sac
iv.cagr..hhz.d.2016.208.133558.sac  iv.cagr..hhz.d.2016.208.133735.sac  iv.cagr..hhz.d.2016.208.133908.sac  iv.cagr..hhz.d.2016.208.133923.sac
iv.cagr..hhz.d.2016.208.134135.sac  iv.cagr..hhz.d.2016.208.134323.sac  iv.cagr..hhz.d.2016.208.134343.sac  iv.cagr..hhz.d.2016.208.134437.sac
iv.cagr..hhz.d.2016.208.134514.sac  iv.cagr..hhz.d.2016.208.134536.sac  iv.cagr..hhz.d.2016.208.134716.sac  iv.cagr..hhz.d.2016.208.134943.sac
iv.cagr..hhz.d.2016.208.135034.sac  iv.cagr..hhz.d.2016.208.135144.sac  iv.cagr..hhz.d.2016.208.135243.sac  iv.cagr..hhz.d.2016.208.135323.sac
iv.cagr..hhz.d.2016.208.135423.sac  iv.cagr..hhz.d.2016.208.135443.sac  iv.cagr..hhz.d.2016.208.135523.sac  iv.cagr..hhz.d.2016.208.135536.sac
iv.cagr..hhz.d.2016.208.135543.sac  iv.cagr..hhz.d.2016.208.135643.sac  iv.cagr..hhz.d.2016.208.135723.sac  iv.cagr..hhz.d.2016.208.135834.sac
iv.cagr..hhz.d.2016.208.135916.sac  iv.cagr..hhz.d.2016.208.140033.sac  iv.cagr..hhz.d.2016.208.140136.sac  iv.cagr..hhz.d.2016.208.140237.sac
iv.cagr..hhz.d.2016.208.140305.sac  iv.cagr..hhz.d.2016.208.140337.sac  iv.cagr..hhz.d.2016.208.140356.sac  iv.cagr..hhz.d.2016.208.140456.sac
iv.cagr..hhz.d.2016.208.140525.sac  iv.cagr..hhz.d.2016.208.140703.sac  iv.cagr..hhz.d.2016.208.140727.sac  iv.cagr..hhz.d.2016.208.140813.sac
iv.cagr..hhz.d.2016.208.140924.sac  iv.cagr..hhz.d.2016.208.140943.sac  iv.cagr..hhz.d.2016.208.141043.sac  iv.cagr..hhz.d.2016.208.141106.sac
iv.cagr..hhz.d.2016.208.141123.sac  iv.cagr..hhz.d.2016.208.141157.sac  iv.cagr..hhz.d.2016.208.141233.sac  iv.cagr..hhz.d.2016.208.141344.sac
iv.cagr..hhz.d.2016.208.141737.sac  iv.cagr..hhz.d.2016.208.141743.sac  iv.cagr..hhz.d.2016.208.141756.sac  iv.cagr..hhz.d.2016.208.141933.sac
iv.cagr..hhz.d.2016.208.141944.sac  iv.cagr..hhz.d.2016.208.142038.sac  iv.cagr..hhz.d.2016.208.142135.sac  iv.cagr..hhz.d.2016.208.142138.sac
iv.cagr..hhz.d.2016.208.142223.sac  iv.cagr..hhz.d.2016.208.142457.sac  iv.cagr..hhz.d.2016.208.142517.sac  iv.cagr..hhz.d.2016.208.142537.sac
iv.cagr..hhz.d.2016.208.142543.sac  iv.cagr..hhz.d.2016.208.142637.sac  iv.cagr..hhz.d.2016.208.142716.sac  iv.cagr..hhz.d.2016.208.142736.sac
iv.cagr..hhz.d.2016.208.142838.sac  iv.cagr..hhz.d.2016.208.142938.sac  iv.cagr..hhz.d.2016.208.142944.sac  iv.cagr..hhz.d.2016.208.143035.sac
iv.cagr..hhz.d.2016.208.143137.sac  iv.cagr..hhz.d.2016.208.143224.sac  iv.cagr..hhz.d.2016.208.144159.sac  iv.cagr..hhz.d.2016.208.144215.sac
iv.cagr..hhz.d.2016.208.144324.sac  iv.cagr..hhz.d.2016.208.144337.sac  iv.cagr..hhz.d.2016.208.144355.sac  iv.cagr..hhz.d.2016.208.144446.sac
iv.cagr..hhz.d.2016.208.144537.sac  iv.cagr..hhz.d.2016.208.144743.sac  iv.cagr..hhz.d.2016.208.144845.sac  iv.cagr..hhz.d.2016.208.144956.sac
iv.cagr..hhz.d.2016.208.145137.sac  iv.cagr..hhz.d.2016.208.145337.sac  iv.cagr..hhz.d.2016.208.145355.sac  iv.cagr..hhz.d.2016.208.145443.sac
iv.cagr..hhz.d.2016.208.145537.sac  iv.cagr..hhz.d.2016.208.145553.sac  iv.cagr..hhz.d.2016.208.145715.sac  iv.cagr..hhz.d.2016.208.145757.sac
iv.cagr..hhz.d.2016.208.150043.sac  iv.cagr..hhz.d.2016.208.150143.sac  iv.cagr..hhz.d.2016.208.150236.sac  iv.cagr..hhz.d.2016.208.150344.sac
iv.cagr..hhz.d.2016.208.150454.sac  iv.cagr..hhz.d.2016.208.150544.sac  iv.cagr..hhz.d.2016.208.150736.sac  iv.cagr..hhz.d.2016.208.150826.sac
iv.cagr..hhz.d.2016.208.151114.sac  iv.cagr..hhz.d.2016.208.151206.sac  iv.cagr..hhz.d.2016.208.151354.sac  iv.cagr..hhz.d.2016.208.151445.sac
iv.cagr..hhz.d.2016.208.151605.sac  iv.cagr..hhz.d.2016.208.151623.sac  iv.cagr..hhz.d.2016.208.151837.sac  iv.cagr..hhz.d.2016.208.152444.sac
iv.cagr..hhz.d.2016.208.153233.sac  iv.cagr..hhz.d.2016.208.153738.sac  iv.cagr..hhz.d.2016.208.154623.sac  iv.cagr..hhz.d.2016.208.155053.sac
iv.cagr..hhz.d.2016.208.155145.sac  iv.cagr..hhz.d.2016.208.155733.sac  iv.cagr..hhz.d.2016.208.155745.sac  iv.cagr..hhz.d.2016.208.155853.sac
iv.cagr..hhz.d.2016.208.155937.sac  iv.cagr..hhz.d.2016.208.161544.sac  iv.cagr..hhz.d.2016.208.164058.sac  iv.cagr..hhz.d.2016.208.164637.sac
iv.cagr..hhz.d.2016.208.164705.sac  iv.cagr..hhz.d.2016.208.164726.sac  iv.cagr..hhz.d.2016.208.165706.sac  iv.cagr..hhz.d.2016.208.171016.sac
iv.cagr..hhz.d.2016.208.171135.sac  iv.cagr..hhz.d.2016.208.171513.sac  iv.cagr..hhz.d.2016.208.171556.sac  iv.cagr..hhz.d.2016.208.171723.sac
iv.cagr..hhz.d.2016.208.172005.sac  iv.cagr..hhz.d.2016.208.172044.sac  iv.cagr..hhz.d.2016.208.172438.sac  iv.cagr..hhz.d.2016.208.180648.sac
iv.cagr..hhz.d.2016.208.192841.sac

---------- 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


Last edited by kristinu; 02-18-2018 at 02:33 PM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List specific files from directories

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)
Discussion started by: Filippo
4 Replies

2. Shell Programming and Scripting

grep'ing for specific directories, and using the output to move files

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)
Discussion started by: JayC89
1 Replies

3. Shell Programming and Scripting

compare files in two directories and output changed files to third directory

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)
Discussion started by: bkeep
4 Replies

4. Shell Programming and Scripting

Recursively move directories along with files/specific files

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)
Discussion started by: frintocf
8 Replies

5. Shell Programming and Scripting

running C program to output in multiple locations

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)
Discussion started by: Jatsui
9 Replies

6. Shell Programming and Scripting

Find specific files only in current directory...not sub directories AIX

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)
Discussion started by: aakishore
2 Replies

7. Solaris

A way to list directories that contain specific files.

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)
Discussion started by: jsabo40
2 Replies

8. Shell Programming and Scripting

How to delete all the files and folders inside all the directories except some specific directory?

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)
Discussion started by: Little
7 Replies

9. UNIX for Beginners Questions & Answers

Move several files into specific directories with a loop

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)
Discussion started by: SonnyClark
14 Replies
All times are GMT -4. The time now is 04:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy