Rename fail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename fail
# 1  
Old 04-03-2009
Rename fail

I've a lot of file with an hyphen on filename, so I use rename for remove him ad substitute with an underscore but it fails

Code:
$ rename 's/\-/\_/' *
Unknown option: _
Unknown option: i
Unknown option: r
Unknown option: e
Unknown option: e
Unknown option: _
Unknown option: g
Unknown option: r
Unknown option: a
Unknown option: d
Unknown option: i

How I can do this?Thanks
# 2  
Old 04-03-2009
Try:
Code:
for SFILE in `ls *-*`; do
  TFILE=`echo "${SFILE}" | sed '/-/_/g'`
  echo mv ${SFILE} ${TFILE}
  mv ${SFILE} ${TFILE}
done

# 3  
Old 04-03-2009
Code:
for file in *-*; do mv "$file" "${file//-/}"; done

# 4  
Old 04-03-2009
quote=TonyFullerMalv;302303867]Try:
Code:
for SFILE in `ls *-*`; do
  TFILE=`echo "${SFILE}" | sed '/-/_/g'`
  echo mv ${SFILE} ${TFILE}
  mv ${SFILE} ${TFILE}
done

[/quote]


Use this it works
Code:
#!/bin/ksh
for SFILE in `ls *-*`; do
  TFILE=`echo "${SFILE}" | sed s/-/_/g`
  mv ${SFILE} ${TFILE}
  print
done

# 5  
Old 04-04-2009
Quote:
Originally Posted by siquadri
quote=TonyFullerMalv;302303867]Try:
Code:
for SFILE in `ls *-*`; do
  TFILE=`echo "${SFILE}" | sed '/-/_/g'`
  echo mv ${SFILE} ${TFILE}
  mv ${SFILE} ${TFILE}
done


Use this it works
Code:
#!/bin/ksh
for SFILE in `ls *-*`; do
  TFILE=`echo "${SFILE}" | sed s/-/_/g`
  mv ${SFILE} ${TFILE}
  print
done

[/QUOTE]

forget the use of ls, it will break if filenames have spaces. Use shell expansion.
# 6  
Old 04-04-2009
Try this:

Quote:
find . -name "*-*" |awk '{ src=$0; gsub(/-/,"_",$0); system("mv "src" "$0); }'
# 7  
Old 04-04-2009
Quote:
Originally Posted by dennis.jacob
Try this:
have you tested it., especially on files with spaces as well?
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