Rename fail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename fail
# 8  
Old 04-04-2009
Quote:
Originally Posted by ghostdog74
have you tested it., especially on files with spaces as well?
It has been asked for "I've a lot of file with an hyphen on filename, "
# 9  
Old 04-04-2009
Quote:
Originally Posted by dennis.jacob
It has been asked for "I've a lot of file with an hyphen on filename, "
yes, so have you actually tested your command out.? create some files with hyphens as well as spaces in their filename (and in different directories since you are using find). then run your command and see if it turns out well?
# 10  
Old 04-04-2009
Quote:
Originally Posted by ghostdog74
yes, so have you actually tested your command out.? create some files with hyphens as well as spaces in their filename (and in different directories since you are using find). then run your command and see if it turns out well?
See my friend, the request is not for replacing filenames with spaces to "-".
The problem here is to replace "-" to "_".Please read the first post.

I have tested my script for this purpose and it works fine.


Thanks.
# 11  
Old 04-04-2009
Quote:
Originally Posted by dennis.jacob
See my friend, the request is not for replacing filenames with spaces to "-".
The problem here is to replace "-" to "_".Please read the first post.

I have tested my script for this purpose and it works fine.


Thanks.
i know. what i am saying is, IF he has files like these:

Code:
# ls -ltr
total 4
-rw-r--r-- 1 root root    0 Apr  4 10:32 file1 - test.txt
drwxr-xr-x 2 root root 4096 Apr  4 10:34 test

# ls -1R *
file1 - test.txt

test:
file - file1 - sdfdf.txt
file2-text.txt

# find . -name "*-*" |awk '{ src=$0; gsub(/-/,"_",$0); system("mv "src" "$0); }'
mv: target `test.txt' is not a directory
mv: target `sdfdf.txt' is not a directory

see what i mean?
# 12  
Old 04-04-2009
Version to deal with spaces in filenames and an unknown number of files.

#!/bin/ksh
find . -name \*\-\* -type f -print | while read FILENAME
do
NEW_FILENAME=`echo "${FILENAME}"|sed -e "s/-/_/g"`
# Remove echoes only if you are tested and happy
echo "OLD FILENAME: ${FILENAME}"
echo "NEW FILENAME: ${NEW_FILENAME}"
echo mv "${FILENAME}" "${NEW_FILENAME}"
done
# 13  
Old 04-06-2009
thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Forum Support Area for Unregistered Users & Account Problems

Fail to register

After inputted all required fields in registration page, the below message is shown and cannot go on. A required field called Custom Date & Time Formats is missing or has an invalid value. (2 Replies)
Discussion started by: Unregistered
2 Replies

2. Shell Programming and Scripting

Untar fail

Hi Team, I have a file named as follows: aaa.tar.gz Now I need to verify if the untar fails, then the script has to send a mail. In order to check this condition, I need a tar.gz file which is unable to untar it. Can anyone help me to create a file which I will be able to unzip successfully... (2 Replies)
Discussion started by: kmanivan82
2 Replies

3. Red Hat

Cluster form fail

why does my cluster form but fail after a few minutes, or why do my multicast communications stop working after a short amount of time? (1 Reply)
Discussion started by: gema.utama
1 Replies

4. Linux

Telnet fail

Hi, I try to telnet to server: # telnet xx.xxx.1.72 1521 Trying xx.xxx.1.72... telnet: connect to address xx.xxx.1.72: Connection refused telnet: Unable to connect to remote host: Connection refused iptables is off: # service iptables status Firewall is stopped. # And I have edit... (4 Replies)
Discussion started by: mehrdad68
4 Replies

5. Shell Programming and Scripting

Why does my test fail ??

Hello, I am stuck... i dunno why does my test fail... any idea ? #!/bin/bash dos2unix info.txt Distor=Distributeur LINE=$(cat info.txt | sed -n 1p) echo $LINE echo $Distor echo "" echo "123-$LINE-123" echo "123-$Distor-123" if ; then LINE2=$(cat info.txt | sed -n 2p) echo $Distor... (14 Replies)
Discussion started by: patx
14 Replies

6. AIX

en0 fail to up.

This is a LPAR that i created earlier. I want to set an IP address to en0 but it failed. Command: failed stdout: yes stderr: no Before command completion, additional instructions may appear below. en0 devdbm01 inet0 changed Method error (/usr/lib/methods/chgif): ... (8 Replies)
Discussion started by: wingcross
8 Replies

7. Shell Programming and Scripting

A simple script fail

Hi, I am a programming newbie, I have started learning C++ a couple of months ago. Unfortunately I don't have too much time in my hands to learn it properly. I need to write a simple script for a project I am doing but I am failing quite hard :mad: (the fact that I am learning C++ is completely... (3 Replies)
Discussion started by: Akhlore
3 Replies

8. Shell Programming and Scripting

fail on comparison

Hi Am having 2 files. I have one data file. before inserting in to the table am taking cout of the data file and store as data 1. After insert in to the table and am taking the count from the table and store as data2. If i try to compare those values If then echo "data match"... (5 Replies)
Discussion started by: bobprabhu
5 Replies

9. UNIX for Dummies Questions & Answers

curl and --fail option

--fail seems to not be working in cURL. When using cURL to download multiple files, --fail is supposed to keep cURL from making files that don't exist, on 404 errors. But when I use --fail or -f, it still makes those files. I've tried it on both Cygwin cURL and Win32 cURL. Anyone know anything... (2 Replies)
Discussion started by: Pulseczar
2 Replies

10. UNIX for Dummies Questions & Answers

Mail fail

I am using the shell script file to send mail by "mailx". I do this by cron job, there is no error found. But it is fail, any suggest to me? How can I resend it automatically? Is there any resend logic by using the mailx? (3 Replies)
Discussion started by: adela
3 Replies
Login or Register to Ask a Question