Find and rename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and rename
# 1  
Old 09-29-2008
Find and rename

Hi,

I was wondering if there is a way to find a particular file and then give it as an input to a program and then dump it into another file.

Something like this:

Code:
find ./ -name '*.txt' -exec ~/processText {} > mod.<current_file> \;

I've been trying all sorts of weird things but not getting any good result. Could someone please help me out?
# 2  
Old 09-29-2008
You cannot do redirection inside the -exec.

You could externalize the redirect. Save this as $HOME/procmod:

Code:
#!/bin/sh
exec $HOME/processText "$1" >mod."$1"

and then run

Code:
find . -name '*.txt' -exec $HOME/procmod {} \;

A more elegant solution would be to avoid the temporary script. You can actually specify it in-line if you spawn a shell and run the redirect using that shell:

Code:
find . -name '*.txt' -exec sh -c "$HOME/processText {} >mod.{}" \;

# 3  
Old 09-29-2008
Thank You so much... That helped! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trying to find and rename files

but it's not working. Hello all. I'm running the following command to find files with a specific name and rename them, but the command prompt returns a short 10 seconds after executing and doesn't find or rename anything. What am I doing wrong here? find . -type f | for file in... (3 Replies)
Discussion started by: bbbngowc
3 Replies

2. Shell Programming and Scripting

How to rename lots of files with find?

Can someone help me with this script. I have a bunch of files like this: "2209OS_02_Code" "2209OS_03_Code" "2209OS_04_Code" "2209OS_05_Code" "2209OS_06_Code" "2209OS_07_Code" "2209OS_08_Code" "2209OS_09_Code" "2209OS_10_Code" "2209OS_10_video" and I want to rename them to be like this: ... (2 Replies)
Discussion started by: siegfried
2 Replies

3. Shell Programming and Scripting

Find and rename part of a file

hi, Need your help. I need to write a script for below.. i have two files in directory /home/abc as below: Watch_20140203_abc.dat Watchnow_20140203_abc.dat I have to copy this file from /home/abc to /home01/home02 after that i have to rename the date part in above two files... (1 Reply)
Discussion started by: Vivekit82
1 Replies

4. UNIX for Advanced & Expert Users

Find Gzip rename and mv

Hi all, what i'm trying to configure its to the following, find all files older then 1 min,gzip them ,rename/move with date and extension .gz (example tes.log_2012-07-26.gz) and trying to move them to another folder (gzipped),the command i'm typing its this, find /home/charli/Desktop/test/ -type... (4 Replies)
Discussion started by: charli1
4 Replies

5. Shell Programming and Scripting

Find directories with same name and rename them

Hello Im trying to make a script in bash shell programming to find subdirectories with the same name into the same directory and rename one of them!! Could you please help me? Thanks in advance (1 Reply)
Discussion started by: BTKBaaMMM
1 Replies

6. Shell Programming and Scripting

Problem with Find and rename file

I want to find a file say IIFT and check its size is zero or not. If its zero then I have to rename anothe file say WWFT , which is in another folder to WWFT$Todaysdate. I tried below command: cd dir2 (*File WWFT is in dir2) find dir/ -type f -name 'IIFT*' -size 0 -exec mv WWFT... (3 Replies)
Discussion started by: ammbhhar
3 Replies

7. Shell Programming and Scripting

Find and Rename File using Terminal

I need help finding a file through terminal and then renaming it automatically. Here is what I have so far to find the file: cd /User/Applications find . */SourceM.app/banner.png | while read line; do mv "$line" banner-.png; done I want the script to rename the file "banner.png" to... (6 Replies)
Discussion started by: rbisconti97
6 Replies

8. Shell Programming and Scripting

Find and Rename files using (find mv and sed)

In response to a closed thread for degraff63 at https://www.unix.com/shell-programming-scripting/108882-using-mv-find-exec.html the following command might do it as some shells spit it without the "exec bash -c " part: Find . -name "*.model" -exec bash -c "mv {} \`echo {} | sed -e 's//_/g'\`"... (0 Replies)
Discussion started by: rupert160
0 Replies

9. Shell Programming and Scripting

Find last updated files and rename

HI I have a requirement to find the last updated files from a directory whcih has subdirectories and inside them we have files with .txt,.doc,.xls .. extensions. i have to find those files which were updated in the last 1hr and rename the files with respective <sub-directory>_<filename> and copy... (3 Replies)
Discussion started by: ramse8pc
3 Replies

10. UNIX for Dummies Questions & Answers

Find and rename all folders with name X.

Is there a command I can use to rename all directories with a certain name to a new name. For instance from my root directory I want to change all folders named '123' to '321' that are in the root directory or any subdirectory. Thanks in advance! (6 Replies)
Discussion started by: mkingrey
6 Replies
Login or Register to Ask a Question