Selecting/using part of directory names in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Selecting/using part of directory names in script
# 1  
Old 09-04-2015
Selecting/using part of directory names in script

I'm making a shell script to:

-copy directories to a new location
-perform conversions on the files within the copied directories
-move the newly created files to a new directory

Please see my super basic script and notes below... and thank you thank you thank you in advance !!



Code:
#created 9/4, KZ

subjid=SWJNaudio04  #subject info 
value=0* 


cd /data2/SWJN/Originals/${subjid}/bold/
cp -r 0* ../../../NIFTI/${subjid}/bold

#these first two lines (above) copy all directories starting with 0 (012, 014, 028, etc.) to the desired new location

cd ../../../NIFTI/${subjid}/bold

#below is where my problem is. mri_convert uses the following format: mri_convert -options /desired/input/path/and/filename /desired/output/path/filename. my problem is that within each /${subjid}/bold/ directory, there are multiple folders (all starting with '0') each containing multiple bshort and hdr files (all starting with 'f_0') and I would like to run the converter/repeat the conversion for every bshort file in each of these directories. I can't just type the actual directory and file numbers because they will differ for each subject. I would ideally like a way to select the numbers from each directory and filename so that the same numbers can be used in the output. I tried to use 0* and f_0*, respectively, to run the converter for all files beginning with 'f_0' in all directories beginning with '0' but this obviously will not work lol

Code:
for f in ${value} ; do mri_convert -it bshort -ot nii /data2/SWJN/Original/${subjid}/bold/${value}/f_${value}.bshort /data2/SWJN/NIFTI/${subjid}/bold/${subjid}_${value}



mkdir NIFTI
mv  *.nii  /NIFTI/
#this will move the newly created .nii files to new directory


Last edited by Corona688; 09-04-2015 at 12:59 PM..
# 2  
Old 09-04-2015
man find, see -exec option

Alternatively use find combined with xargs.
This User Gave Thanks to cjcox For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Problem with shell script while spaces encountered in directory names

Hi, I am having issues with the jar -tf command when I put in the shell script. The command runs fine from the command line as shown below. # jar -tf "./VirtualBox Dropped Files/2016-04-17T20:58:49.129139000Z/hive-exec-0.8.1.jar" But when I put in a shell script(shown below) and the... (10 Replies)
Discussion started by: vinoo128
10 Replies

2. Shell Programming and Scripting

Need script to pass all sql file names in a directory to DB query

Hi All, In this path /home/all_files we have follwing files and direcotries proc_edf_sot.sql proc_ssc_sot.sql func_dfg_sot.sql sot unic cmr sdc under sot directory we have other directories sql pas ref under sql directory we have sql_sot sql_mat (6 Replies)
Discussion started by: ROCK_PLSQL
6 Replies

3. Shell Programming and Scripting

List the file names available on FTP server before selecting the required file

Below is my script code.which shows the environment name and then fetch the file from the ftp server but I am facing one issue.The script should be run in both way.We can pass the arguments with script and select the environment name then file name.Here the issue is I am not able to list the files... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

4. Shell Programming and Scripting

Script to list the file names in a directory

Hi all, I need a shell script to write into a .txt file the no of files in a directory with extension and separated by comma in between. For eg, a directory contains files like a.csv b.csv c.csv d.csv Then the output in the output.txt file should be like a.csv,b.csv,c.csv,d.csv ... (3 Replies)
Discussion started by: dubuku_01
3 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. UNIX for Dummies Questions & Answers

Remove part of file names in a directory

Hi, i have a directory full of pictures, .jpg files. Half of them begin with "beach_" (for ex beach_123_123456.jpg) i'm looking for a command to remove the "beach_" from all files in the directory. thanks (4 Replies)
Discussion started by: robertmanalio
4 Replies

7. UNIX for Dummies Questions & Answers

Loop through directory and extract sub directory names

I am trying to loop through folders and extract the name of the lowest level subfolder I was running the script below, it returns /bb/bin/prd/newyork /bb/bin/prd/london /bb/bin/prd/tokyo I really want newyork london tokyo I couldn't find a standard variable for the lowest level... (1 Reply)
Discussion started by: personalt
1 Replies

8. UNIX for Dummies Questions & Answers

Deleting part of file names

My server got messed up and the names of my files were not completely processed. As results I ended up getting a bunch of files with the following names: I need to remove the underscore and everything before it. Thus, the files will be renamed to something like this: Any help will be greatly... (3 Replies)
Discussion started by: Xterra
3 Replies

9. Shell Programming and Scripting

Selecting a part of the text (regex pattern, awk, sed)

Hello, let's start by giving you guys a few examples of the text: "READ /TEXT123/ABC123" "READ /TEXT123/ABC123/" "READ TEXT123/ABC123" "READ TEXT123/ABC123/" "READ TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123/" TEXT and ABC can be and I... (5 Replies)
Discussion started by: TehOne
5 Replies

10. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies
Login or Register to Ask a Question