editing names of files in multiple folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting editing names of files in multiple folder
# 1  
Old 04-06-2011
editing names of files in multiple folder

I have 1000's of directories which is named as numbers. Each directory contains multiple files. Each of these directories have a file named "att". I need to rename all the att files by adding the directory name followed by "_" then att for each of the directories.

Code:
Directories
120 
      att

130
      att

what I need is:
Code:
120 
     120_att

130
      130_att

IIs there a way to do it using awk or sed for 1000's of such directories
# 2  
Old 04-06-2011
something like this might work. you may have to adjust it for your env.

Code:
find /yourdirname -name 'att' | while read line; do DIR=`basename $(dirname $line)`; mv att "$DIR_att"; done

HTH.
-RN.
# 3  
Old 04-06-2011
Code:
find . -type f -name att | nawk -F/ '{print "mv", $0, $(NF-1)"_" $NF}'

Once satisfied with the output:
Code:
find . -type f -name att | nawk -F/ '{print "mv", $0, $(NF-1)"_" $NF}' | sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute multiple files in multiple folders and also output on same folder

How to execute multiple files in multiple folders and also output to be generated in the same folder? Hello Team, I have a path like Sanity_test/*/* and it has around 100+ folders inside with files. I would like to run/execute those files and output of execution to be placed on same /... (1 Reply)
Discussion started by: pushpabuzz
1 Replies

2. Shell Programming and Scripting

Script to tar/rsync/rm multiple folder names

hi all, i attach a link with what im trying to do automatically via script but i have some questions i need answering please, bear in mind i am really new to bash scripting, the only thing i know how to do is commands in scripts like cd rm tar rsync cp stuff like that i have mutiple project... (48 Replies)
Discussion started by: robertkwild
48 Replies

3. Shell Programming and Scripting

Checking Multiple File existance in a UNIX folder(Note: File names are all different)

HI Guys, I have some 8 files with different name and extensions. I need to check if they are present in a specific folder or not and also want that script to show me which all are not present. I can write if condition for each file but from a developer perspective , i feel that is not a good... (3 Replies)
Discussion started by: shankarpanda003
3 Replies

4. UNIX for Dummies Questions & Answers

Editing multiple files with vi, why :p is not working

Hi, Can any gurus advise why :p is not working on my vi? When editing multiple files, :n works and it takes me the next file, but :p which is supposed to take me back to the previous file does not work. Please advise. Thanks in advance. (2 Replies)
Discussion started by: newbie_01
2 Replies

5. Shell Programming and Scripting

Script to move files with similar names to folder

I have in directory /media/AUDIO/WAVE many .mp3 files with names like: my filename_01of02.mp3 my filename_02of02.mp3 Your File_01of06.mp3 Your File_02of06.mp3 etc.... In the same directory, /media/AUDIO/WAVE, I have many folders with names like 9780743579490 9780743579491 etc.. Inside... (7 Replies)
Discussion started by: glev2005
7 Replies

6. Shell Programming and Scripting

How to make an editing script work for multiple files?

Hey everybody, I have a script for making a string substitution in a file. I am trying to modify it in order to make the same modifcation to multiples files. here is what I have so far. #!/bin/csh set p1="$1" shift set p2="$1" shift foreach x ($*) if ( { grep -w -c "$p1" $x } ) then mv... (7 Replies)
Discussion started by: iwatk003
7 Replies

7. Shell Programming and Scripting

Editing files to add some thing in all the files in a folder

Hi All, I have a folder that contains 100's of files and each file have a similar content like the following format: ((STBJa:200.0,((STBTz:200.0,(STSwe:200.0,(STDUw:200.0,(ST4Bu:200.0,STL2b:200.0):127.0):86.0):80.0):120.0, STAHr:200.0):134.0):200.0,STuNg:200.0);What I need is to do is add "#1"... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

8. UNIX for Dummies Questions & Answers

Copying multiple folders to local machine (don't know folder names)

Hi. I'm trying to copy multiple folders from the remote machine to the local machine. I wrote a batch file to run an ftp window. The problem I am having is that the only command to copy files is mget *, and this copies only files, not folders. For example, ftp ts555 cd ts555/test ' test... (5 Replies)
Discussion started by: leenyburger
5 Replies

9. UNIX for Dummies Questions & Answers

Editing multiple file names in one go

Hi there, I have a folder full of pdf's and I've run a compression on the to reduce the size, the output of the compress places a '-o' in the name of the file. Before 12345.pdf After 12345-o.pdf Now I've got around 50000 files that I need to change back to the previous name, is... (3 Replies)
Discussion started by: KeesH
3 Replies

10. UNIX for Dummies Questions & Answers

Editing one string in multiple files

I am trying to edit multiple files from one directory and including all the files in all the sub directories. My string opens each file, puts the text on my screen and does not save the new information to the file. I am using a variable in my script, and wondering if that is what is choking it. ... (1 Reply)
Discussion started by: Skoshi
1 Replies
Login or Register to Ask a Question