Replace Filename and text inside of directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace Filename and text inside of directory
# 1  
Old 11-04-2011
Replace Filename and text inside of directory

I have a directory that has directories that contain Dir-20111114-xyz and I want to change them to Dir-20111121-xyz.

Inside of Dir-20111114-xyz, I have a config.xml file that also contains the date that I need changed from 20111114 to 20111121

I have used sed to replace inside of file not sure how to handle renaming the directories.

Thank you.
# 2  
Old 11-04-2011
Question

You could use the mv command to rename files.

Please be more specific about you file names, what you wrote is confusing. Is the name of files actually "Dir-20111114-xyz"? Or, is part of that trying to show path and name, as in "\dir\2011114\xyz"?
# 3  
Old 11-04-2011
the Directory name is actually "DIR-20111114-xyz" and there is 50 or so with "DIR-20111114-abc" "DIR-20111114-efg"
I want to keep the name intact except for the changing of the date.
# 4  
Old 11-04-2011
Code:
OLDDATE=20111114
NEWDATE=yyyymmdd

for DIR in DIR-"${OLDDATE}"-*
do
        sed "s/${OLDDATE}/${NEWDATE}/g" < "${DIR}/config.xml" > "${DIR}/config.xml.new"
        #cat "${DIR}/config.xml.new" > "${DIR}/config.xml"
        # rm "${DIR}/config.xml.new"
        echo mv "${DIR}" "${DIR/${OLDDATE}/${NEWDATE}}"    
done

Remove the #'s and echoes once you've checked the output and the content of the config.xml.new files to make sure it's really done what you want.
# 5  
Old 11-04-2011
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List filename of files only inside a directory (non-recurrsive) on AIX

I wish to list only files along with the absolute path in a given directory on my AiX 6.1 system. Below is the best I could do. ls -p "/app/scripts"/* This gives a a list of all filename along with folder names with absolute path non-recurrsive (without listing files in sub-directories)... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

Cat files listed in text file and redirect to new directory with same filename

I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Discussion started by: trigger467
5 Replies

3. Shell Programming and Scripting

Check if files inside a text file are found under a directory

Hi all, Please somebody help me with this: I want to check if the files listed in a text file, are found under a directory or not. For example: the file is list_of_files.txt, which contains inside this rows: # cat list_of_files logs errors paths debug # I want to check if these... (3 Replies)
Discussion started by: arrals_vl
3 Replies

4. Shell Programming and Scripting

Replace text inside XML file based on condition

Hi All, I want to change the name as SEQ_13 ie., <Property Name="Name">SEQ_13</Property> when the Stage Type is PxSequentialFile ie., <Property Name="StageType">PxSequentialFile</Property> :wall: Input.XML <Main> <Record Identifier="V0S13" Type="CustomStage" Readonly="0">... (3 Replies)
Discussion started by: kmsekhar
3 Replies

5. Shell Programming and Scripting

pattern replace inside text file using sed

Hi, I have a situation where I want to replace some occurrences of ".jsp" into ".html" inside a text file. For Example: If a pattern found like <a href="http://www.mysite.com/mypage.jsp"> it should be retained. But if a pattern found like <a href="../mypage.jsp"> it should be changed to... (4 Replies)
Discussion started by: meharo
4 Replies

6. Shell Programming and Scripting

how to do search and replace on text files in directory

I was google searching and found Perl as a command line utility tool This almost solves my problem: find . | xargs perl -p -i.old -e 's/oldstring/newstring/g' I think this would create a new file for every file in my directory tree. Most of my files will not contain oldstring and I... (1 Reply)
Discussion started by: siegfried
1 Replies

7. Shell Programming and Scripting

Replace text with filename

Hi, I have a few thousand files, each contains the word "hello". Would it be possible to do a batch job that replaces the word hello with the filename? Thanks. (2 Replies)
Discussion started by: calrog
2 Replies

8. Shell Programming and Scripting

Sed , Replace a "variable text" inside of a statement

Please Help... I am trying to manipulte the following line Before : <user:Account_Password>002786</user:Account_Password> the password is the "variable", i need to delete / omit the password in the file, (it occurs several thousand times) so the tag line looks like After:... (4 Replies)
Discussion started by: jackn7
4 Replies

9. Shell Programming and Scripting

how to replace a text inside a file based on a xml key

<c-param> <param-name>Number</param-name> <param-value>22</param-value> <description>my house number</description> </c-param> <c-param> <param-name>Address</param-name> ... (4 Replies)
Discussion started by: reldb
4 Replies

10. UNIX for Advanced & Expert Users

Replacing text inside a directory

This is my first post to this group.I am new to Unix.I have one requirement I need to replace a text in all the files in a directory and sub-directory.Eg i have a folder structure like /usr/local/abc , inside abc i have several directories and several files. All the files inside abc and all the... (1 Reply)
Discussion started by: vatsan
1 Replies
Login or Register to Ask a Question