Simple renaming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple renaming
# 1  
Old 01-05-2012
Simple renaming

Hi

Having many filenames in a folder containing the string "-DATE" (e.g. : Nbr_Name-DATE_2011.txt). I would like to remove the "-DATE" in each filename to get just: Nbr_Name_2011.txt . Know its easy but somehow it wont work. Tried it like that:
Code:
for i in `ls *-DATE*`; do mv "$i" "${i/-DATE/}";

but its not working....

Thanks for answers
Jurgen
# 2  
Old 01-05-2012
Hope this helps:

Code:
for i in *-DATE*;do mv -vv "$i" "${i/\-DATE/}";done

`Nbr_Name-DATE_2011.txt' -> `Nbr_Name_2011.txt'

# 3  
Old 01-05-2012
thanks for the help but its not working, i got the error message: "${i/\-DATE/}": bad substitution....
(using ksh)
Jurgen
# 4  
Old 01-05-2012
Hi,

Your code

Code:
for i in `ls *-DATE*`; do mv "$i" "${i/-DATE/}";

New Code:-

Code:
for i in `ls *-DATE*`; do mv "$i" "${i/-DATE/}"; done

Note :- Just add "done" to your code
Smilie
# 5  
Old 01-05-2012
my code is producing the same error message than the suggestion of in2nix4life....bad substitution
# 6  
Old 01-05-2012
Try the new code given above ,

I have tried in LINUX(REH4) , using bash shell.
# 7  
Old 01-05-2012
not working....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

A Simple Clock, Well Maybe Not That Simple...

The attachment says it all really... It is a DEMO at a glance digital readout using the "date" command to make it useful... For a Mocbook Pro 13", OSX 10.7.5, but may well work on Linux variants too. Enjoy... #!/bin/bash # # Clock.sh # A bash DEMO to create a 6 x 7 character set... (4 Replies)
Discussion started by: wisecracker
4 Replies

2. Windows & DOS: Issues & Discussions

Simple renaming question

I want to rename all fileextensions inside a folder that are called ".srt.ass" to just ".ass" My (poor code so far is): or %x in (*.srt.ass) do RENAME "*.srt.ass" "*.ass" Thanks in advance. (4 Replies)
Discussion started by: pasc
4 Replies

3. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

4. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

5. UNIX for Dummies Questions & Answers

renaming

Hi, I wrote a script to rename all files in a directory from uppercase to lowercase and changing spaces to underscores: #!/bin/sh echo "rename" read pathname cd $pathname for f in `ls "$pathname"` ; # listing directory for all files do echo... (1 Reply)
Discussion started by: the.noob
1 Replies

6. Shell Programming and Scripting

Simple renaming task?

Hi guys, could someone tell me how i could create a label like this: mybox01, mybox04, mybox12, mybox10 when i have the values "mybox1", "mybox4","mybox12","mybox10" as a prefix and a number. If the number is below 10 then add a zero before the number? A one liner? A long approach is to... (2 Replies)
Discussion started by: muay_tb
2 Replies

7. Shell Programming and Scripting

Simple to you not simple to me pattern matchin help

hey all, im new and my first question is: say i have a word "blahblah" how do i get and replace the last letter of the word with say k, so replace the h with a k. However you cant just replace the h it has to change the LAST LETTER of the word. Cheers In advance. :b: (0 Replies)
Discussion started by: aleks001
0 Replies

8. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

9. UNIX for Dummies Questions & Answers

simple batch renaming...45-*.php to 46-*.php

in Bash i'm trying to rename directories full of files. the file name pretty much stays the same except for the numerical prefix which will be the same for all files. so, i want to rename these... 45-body.php 45-header.php 45-footer.php etc. to... 46-body.php 46-header.php... (2 Replies)
Discussion started by: bcamp1973
2 Replies

10. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies
Login or Register to Ask a Question