Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Add part of pathname/subfolder name to beginning of filename Post 302976766 by azurite on Wednesday 6th of July 2016 01:02:20 AM
Old 07-06-2016
Add part of pathname/subfolder name to beginning of filename

Hello everyone,
I need some help renaming files. I have a directory with a bunch of subfolders in it like so with DWI being the working directory and the 3 levels after it being subdirectories
Code:
home/user/Documents/DWI/111180-100/3t_2016-01-07_21-42/003_DTI_siemens_TClessdistort/dtifit_FA.nii.gz
home/user/Documents/DWI/111445-100/3t_2016-01-07_21-42/003_DTI_siemens_TClessdistort/dtifit_FA.nii.gz
etc

Those subfolders all have a couple of files that begin with 'dti' and end in 'nii.gz'
Code:
(ex: dti_FA.nii.gz, dti_V1.nii.gz etc)

I need a script that will loop over all the subfolders and rename the file so that it adds the bolded part of the pathname to the beginning of the file. Example:

Code:
home/user/Documents/DWI/111180-100/3t_2016-01-07_21-42/003_DTI_siemens_TClessdistort/dtifit_FA.nii.gz
home/user/Documents/DWI/111445-100/3t_2016-01-07_21-42/003_DTI_siemens_TClessdistort/dtifit_FA.nii.gz

to rename the file in each subfolder from
Code:
 'dti_FA/V1etc.nii.gz' to 'specifiedstringfrompath_dti_*.nii.gz' or '111180-100_dti_FA/V1etc.nii.gz'

I know I need to use the for loop and perhaps globbing but I don't know how to go about adding that string from the subdirectory to the file?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

part of a filename

Hi, I need to extract only a part of the filenames of some files. The files are named this way : .tap_profile_SIT02 I want the "SIT02" part, which is not the same for each file. I was able to get what I want with bash, but not with ksh. Here is the command I used in bash : find... (8 Replies)
Discussion started by: flame_eagle
8 Replies

2. Shell Programming and Scripting

script to include filename with variations at the beginning of the file

Hi there, I have a bunch of files that I want to modify. As a beginner, but nevertheless enthusiast, in the use of the shell I want to create a script enabling me to modify those files quickly. I had only some partial success with various peaces of scripts but I would like to create one script... (1 Reply)
Discussion started by: iamzesh
1 Replies

3. Shell Programming and Scripting

Link multiple files from different subfolder to a new subfolder

Hi, I have the following subfolder with files: /data/a/1/xxx.txt /data/b/2/yyy.txt /data/c/3/zzz.txt And i have a set of new folders which have exactly the same structure as above but different disk without the files: /data_02/a/1/ /data_02/b/2/ /data_02/c/3/ Now i would like to... (6 Replies)
Discussion started by: total_ysf
6 Replies

4. Shell Programming and Scripting

Getting part of a filename

Hi All, I'm trying to get part of a filename and my skill with regular expression are lacking. I know I need to use SED but have no idea how to use it. I'm hoping that someone can help me out. The file names would be: prefix<partwewant>suffix.extension the prefix and suffix are always 3... (4 Replies)
Discussion started by: imonkey
4 Replies

5. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

6. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Appending beginning of filename to end

Hi Guys, I have serveral directories like this: (2013) blablabla(blabla) - blabla (blabla) or (1997) blablabla(blabla) - blabla (blabla) and have to rename them to something like that: blablabla(blabla) - blabla (blabla) (2013) and blablabla(blabla) - blabla (blabla) (1997) Easy... (2 Replies)
Discussion started by: Nateshift
2 Replies

8. UNIX for Dummies Questions & Answers

Replacing part of filename

Hi guys! I have quite a lot of files like all_10001_ct1212307460308.alf* and I want to get rid of the first number for all at once like: all_ct1212307460308.alf* How can I do this in the shell? (12 Replies)
Discussion started by: TimmyTiz
12 Replies

9. UNIX for Dummies Questions & Answers

Renaming files with part of their pathname and copying them to new directory

Hi I think this should be relatively simple but I can't figure it out. I have several files with the same name in different folders within a directory (the output of a program that I ran). Something like this: ./myAnalysis/item1/round1/myoutput.txt ./myAnalysis/item1/round2/myoutput.txt... (2 Replies)
Discussion started by: jullee
2 Replies

10. Shell Programming and Scripting

Add part of directory name to filename

Hello, I need to add a part of folder name to the files inside it. For instance the file is HMCBackup_20150430.155027.tgz and it is under directory /nim/dr/HMCBackup/cops22 I need to add cops22 to the file name so as it would be cops22_HMCBackup_20150430.155027.tgz Any help in doing... (10 Replies)
Discussion started by: hasn318
10 Replies
IMAGEMATH(1)							   User Commands						      IMAGEMATH(1)

NAME
ImageMath - part of ANTS registration suite DESCRIPTION
Usage: ./ImageMath ImageDimension OutputImage.ext Operator Image1.ext Image2.extOrFloat some options output text files The last two arguments can be an image or float value Valid Operators : m (multiply) , + (add) , - (subtract) , / (divide) , ^ (power) , exp -- take exponent exp(imagevalue*value) addtozero overadd abs total -- sums up values in an image or in image1*image2 (img2 is the probability mask) Decision -- computes result=1./(1.+exp(-1.0*( pix1-0.25)/pix2)) Neg (Produce Image Negative ) , G Image1.ext s (Smooth with Gaussian of sigma = s ) MD Image1.ext s ( Morphological Dilation with radius s ) , ME Image1.ext s ( Morphological Erosion with radius s ) , MO Image1.ext s ( Morphological Opening with radius s ) MC Image1.ext ( Morphological Closing with radius s ) GD Image1.ext s ( Grayscale Dilation with radius s ) , GE Image1.ext s ( Grayscale Erosion with radius s ) , GO Image1.ext s ( Grayscale Opening with radius s ) GC Image1.ext ( Grayscale Closing with radius s ) D (DistanceTransform) , Segment Image1.ext N-Classes LocalityVsGlobalityWeight-In-ZeroToOneRange OptionalPriorImages ( Segment an Image with option of Priors , weight 1 => maximally local/prior-based ) Grad Image.ext S ( Gradient magnitude with sigma s -- if normalize, then output in range [0, 1] ) , Laplacian Image.ext S normalize? ( laplacian computed with sigma s -- if normalize, then output in range [0, 1] ) , Normalize image.ext opt ( Normalize to [0,1] option instead divides by average value ) PH (Print Header) , Byte ( Convert to Byte image in [0,255] ) LabelStats labelimage.ext valueimage.nii ( compute volumes / masses of objects in a label image -- write to text file ) ROIStatistics LabelNames.txt labelimage.ext valueimage.nii ( see the code ) DiceAndMinDistSum LabelImage1.ext LabelImage2.ext OptionalDistImage -- outputs DiceAndMinDistSum and Dice Overlap to text log file + optional dis- tance image Lipschitz VectorFieldName -- prints to cout & writes to image InvId VectorFieldName VectorFieldName -- prints to cout & writes to image GetLargestComponent InputImage {MinObjectSize} -- get largest object in image ThresholdAtMean Image %ofMean FlattenImage Image %ofMax -- replaces values greater than %ofMax*Max to the value %ofMax*Max stack Image1.nii.gz Image2.nii.gz --- will put these 2 images in the same volume CorruptImage Image NoiseLevel Smoothing TileImages NumColumns ImageList* RemoveLabelInterfaces ImageIn EnumerateLabelInterfaces ImageIn ColoredImageOutname NeighborFractionToIgnore FitSphere GM-ImageIn {WM-Image} {MaxRad-Default=5} HistogramMatch SourceImage ReferenceImage {NumberBins-Default=255} {Number- Points-Default=64} PadImage ImageIn Pad-Number ( if Pad-Number is negative, de-Padding occurs ) Where Image ValueToLookFor maskIm- age-option tolerance --- the where function from IDL TensorFA DTImage TensorColor DTImage --- produces RGB values identifying prin- cipal directions TensorToVector DTImage WhichVec --- produces vector field identifying one of the principal directions, 2 = largest eigenvalue TensorToVectorComponent DTImage WhichVec --- 0 => 2 produces component of the principal vector field , i.e. largest ei- genvalue. 3 = 8 => gets values from the tensor TensorIOTest DTImage --- will write the DT image back out ... tests I/O processes for consistency. MakeImage SizeX SizeY {SizeZ} SetOrGetPixel ImageIn Get/Set-Value IndexX IndexY {IndexZ} -- for example ImageMath 2 outimage.nii SetOrGetPixel Image Get 24 34 -- gets the value at 24, 34 ImageMath 2 outimage.nii SetOrGetPixel Image 1.e9 24 34 -- this sets 1.e9 as the value at 23 34 you can also pass a boolean at the end to force the physical space to be used TensorMeanDiffusion DTImage CompareHeadersAndImages Image1 Image2 --- tries to find and fix header error! output is the repaired image with new header. never use this if you trust your header information. CountVoxelDifference Image1 Image2 Mask --- the where function from IDL stack image1 image2 --- stack image2 onto image1 CorrelationUpdate Image1 Image2 RegionRadius --- in voxels , Compute update that makes Image2 more like Image1 ConvertImageToFile imagevalues.nii {Optional-ImageMask.nii} -- will write voxel values to a file PValueImage TValueImage dof ConvertToGaussian TValueImage sigma-float ConvertImageSetToMatrix rowcoloption Mask.nii *images.nii -- each row/column contains image content extracted from mask applied to images in *img.nii ConvertVector- ToImage Mask.nii vector.nii -- the vector contains image content extracted from a mask - here we return the vector to its spatial origins as image content TriPlanarView ImageIn.nii.gz PercentageToClampLowIntensity PercentageToClampHiIntensity x-slice y-slice z-slice TruncateImageIntensity inputImage {lowerQuantile=0.05} {upperQuantile=0.95} {numberOfBins=65} {binary-maskImage} Fill- Holes Image parameter : parameter = ratio of edge at object to edge at background = 1 is a definite hole bounded by object only, 0.99 is close -- default of parameter > 1 will fill all holes PropagateLabelsThroughMask speed/binaryimagemask.nii.gz initiallabelimage.nii.gz Optional-Stopping-Value -- final output is the propagated label image optional stopping value -- higher values allow more distant propagation FastMarchingSegmentation speed/binaryimagemask.nii.gz initiallabelimage.nii.gz Optional-Stopping-Value -- final output is the propagated label image optional stopping value -- higher values allow more distant propagation ExtractSlice volume.nii.gz slicetoextract --- will extract slice number from last dimension of volume (2,3,4) dimensions ConvertLandmarkFile InFile.txt ---- will convert landmark file between formats. see ants.pdf for description of formats. e.g. ImageMath 3 outfile.vtk ConvertLandmarkFile infile.txt ImageMath 1.9 May 2012 IMAGEMATH(1)
All times are GMT -4. The time now is 04:53 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy