Sponsored Content
Top Forums Shell Programming and Scripting file name shortening for multiple directories Post 302691549 by giseismology on Friday 24th of August 2012 07:54:17 PM
Old 08-24-2012
file name shortening for multiple directories

there was a post previously about this from around 2010
but i was unable to get the suggested scripts there to work.

the following code works for me when it's saved inside the
directory of files whose names i want to shorten, but i would
like to be able to store it in a file with a list of
directories and have it enter into each directory, shorten the
file names in that directory, and then move to the next
directory.

basically enter directory1 and perform the code below,
move to directory2 and do it again, then directory3, etc. etc.

thanks in advance for any help!

Code:
rename_seq () 
{   
seq=1   
oldname="$1"   
newname="$2"   
ext="$3"   
while [ -e "$newname$(printf "%02d" $seq).$ext" ]; do     
(( seq ++ ))   
done   
mv "$oldname.$ext" "$newname$(printf "%02d" $seq).$ext" 
}  

ls | while read name; do   
ext="${name##*.}"   
name="${name%.*}"   
newname="${name//[<>=?:;\"*+,|]/_}"   
newname="${newname:0:38}"   
if [ -e "${newname}.$ext" ]; then     
rename_seq "$newname" "$newname" "$ext"   
fi   
if [ -e "${newname}"??".$ext" ]; then     
rename_seq "$name" "$newname" "$ext"   
else     mv "$name.$ext" "$newname.$ext"   
fi 
done


Last edited by methyl; 08-24-2012 at 09:08 PM.. Reason: please use code tags for code and data.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

moving directories to new directories on multiple servers

Hi - I am new to unix scripts...I need to move several directories on multiple servers to new directories. (0 Replies)
Discussion started by: mackdaddy07
0 Replies

2. UNIX for Dummies Questions & Answers

Copy single file to multiple directories

Please help - I need to copy a single file to multiple directories. Dir structure: Parent_Directoy Filename1 Child_Directory1 Child_Directory2 Child_Directory3 Child_Directory4 .... So I need to copy Filename1 to all of the... (2 Replies)
Discussion started by: kthatch
2 Replies

3. Shell Programming and Scripting

read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Discussion started by: fxvisions
5 Replies

4. Shell Programming and Scripting

check if multiple directories exist else create missing directories

Hi , I 'm trying to check if multiple directories exist on a server, if not create the missing ones and print " creating missing directory. how to write this in a simple script, I have made my code complex if ; then taskStatus="Schema extract directory exists, checking if SQL,Count and... (7 Replies)
Discussion started by: ramky79
7 Replies

5. UNIX for Dummies Questions & Answers

Deleting multiple directories inside multiple directories

Hi, Very unfamiliar with unix/linux stuff. Our admin is on vacation so, need help very quickly. I have directories (eg 40001, 40002, etc) that each have one subdirectory (01). Each subdir 01 has multiple subdirs (001, 002, 003, etc). They are same in each dir. I need to keep the top and... (7 Replies)
Discussion started by: kkouraus1
7 Replies

6. UNIX for Dummies Questions & Answers

copy file using unix in multiple directories

Hi All Genious, I want to copy a file name XYZ .In a directory /HOME/dir/IXOS1/dir1 which contain multiple directories named not in pattern want to copy the XYZ in all of the directories available on path /HOME/dir/IXOS1/dir1 . Thanks in advance . (2 Replies)
Discussion started by: mumakhij
2 Replies

7. Shell Programming and Scripting

Reading multiple directories and file from them

Hello I'm making script for Dallas temperature sensors (DS1820). When a sensor is connected, it shows up as a directory in /sys/bus/w1/devices in format 10-xxxxxxx. Inside the directory is a file called w1_slave which holds the temperature in format t=xxxxx. Each sensor has unique... (2 Replies)
Discussion started by: Klipeti
2 Replies

8. Shell Programming and Scripting

Help with create multiple directories under diff file systems

Hi, Need help ...I want to create multiple directories in different /file systems using for loop..eg.../ORCL_data01/oradata/orcl/ctl. ../ORCL_data01/oradata/orcl/data. ../ORCL_data01/oradata/orcl/redo. Script :- ========= for dir in `ls -d... (8 Replies)
Discussion started by: Linux6.5
8 Replies

9. Shell Programming and Scripting

Command to Search a FILE for a STRING in multiple DIRECTORIES

Hi, Can someone please help me with a Command to Search a FILE for a STRING in multiple DIRECTORIES. I am searching for the VIP in HTTPD.CONF in multiple httpd instances. I am using find ./ -name "httpd.conf" | xargs grep 10.22.0.141 cut -d: -f3- | cut -d ' ' -f4 | sort | uniq -c ... (1 Reply)
Discussion started by: crosairs
1 Replies

10. Shell Programming and Scripting

Merge values from multiple directories into one file in awk or bash

I am trying to merge or combine all $1 values in validation.txt from multiple directories into one new file and output it here tab-delimited:/home/cmccabe/Desktop/20x/total/total.txt. Each $2 value and the header would then be a new field in total.txt. I am not sure how to go about this as cat is... (2 Replies)
Discussion started by: cmccabe
2 Replies
GENLIB_COPY_UP_SEG.3(October 1, 1997)									     GENLIB_COPY_UP_SEG.3(October 1, 1997)

NAME
GENLIB_COPY_UP_SEG - copy a physical segment from an instance in the current figure SYNOPSYS
#include <genlib.h> void GENLIB_COPY_UP_SEG(oldname, insname, newname) char *oldname, *insname, *newname; ORIGIN
This software belongs to the ALLIANCE CAD SYSTEM developed by the ASIM team at LIP6 laboratory of Universite Pierre et Marie CURIE, in Paris, France. Web : http://asim.lip6.fr/recherche/alliance/ E-mail : alliance-users@asim.lip6.fr PARAMETERS
oldname Name of the segment in the instance insname Name of the instance in the which the segment is to be searched for newname Name to be given to the segment in the current figure DESCRIPTION
COPY_UP_SEG adds a segment in the current layout cell. All the segment's attributes are copied from the first found segment called oldname in the instance insname. The new segment is given the name newname. The main purpose of this function is to rename a segment, so it can be used later, when extracting a layout. ERRORS
"GENLIB_COPY_UP_SEG impossible : missing GENLIB_DEF_PHFIG" No figure has been yet specified by a call to DEF_PHFIG. So it isn't possible to place a segment inside it. you must call DEF_PHFIG before any other layout action. "illegal getphins : instance insname does not exist" The instance called insname does not currently belong to the figure. "GENLIB_COPY_UP_SEG impossible : segment segname does not exist" The segment segname does not exist in the model of the instance insname. EXAMPLE
#include <genlib.h> main() { /* Create a figure to work on */ GENLIB_DEF_PHFIG("cell"); GENLIB_PLACE("z2l_y", "r1", NOSYM, 23L, 54L); /* Put a segment */ GENLIB_COPY_UP_SEG("mux0_s", "r1", "out_s"); /* Save that on disk */ GENLIB_SAVE_PHFIG(); } SEE ALSO
genlib(1), GENLIB_DEF_PHFIG(3), GENLIB_SAVE_PHFIG(3), GENLIB_PHSEG(3), GENLIB_THRU_H(3), GENLIB_THRU_CON_H(3), GENLIB_THRU_V(3), GEN- LIB_THRU_CON_V(3), GENLIB_WIRE1(3), GENLIB_WIRE2(3), GENLIB_WIRE3(3). BUG REPORT
This tool is under development at the ASIM department of the LIP6 laboratory. We need your feedback to improve documentation and tools. PROCEDURAL GENERATION LANGUAGE
ASIM/LIP6 GENLIB_COPY_UP_SEG.3(October 1, 1997)
All times are GMT -4. The time now is 07:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy