Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Renaming files

Posted on 1999-06-30
12
Medium Priority
?
360 Views
Last Modified: 2010-04-21
I have got around hundred files under a directory called
/accounts/payroll .
Now the files under the above directory look as below.

eg:cs*.bakup*.1999*

Now i have to rename all the files to cs*.abc and put
back in the same directory /accounts/today.

I used the mv command to rename for one file , but
i want to do the same , that is renaming all the files
 with one command .

the syxtax i used is  mv cs0001.bakup1.19990501 cs0001.abc
 The above command worked, but can i rename all the files
at one stretch by modifying the above command.

Thanks in advance,
Pap.






0
Comment
Question by:Papsniper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +3
12 Comments
 
LVL 1

Expert Comment

by:arthurd
ID: 2011294
#!/bin/ksh
cd /accounts/today
ls > /tmp/filelist
exec < /tmp/filelist
while read filename
do
    first=`echo $filename | awk -F. '{print $1}'`
    mv $filename $first.abc
done
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2011295
ls * | awk -F. '{print "mv "$0" /accounts/today/"$1".abc";}' |sh
0
 

Author Comment

by:Papsniper
ID: 2011296
pl check to see that the problem is different.

Pap.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Papsniper
ID: 2011297
Hi ,
could anybody answer my question which has got the title
'renaming files'.

Thanks,
Pap.


0
 
LVL 1

Expert Comment

by:arthurd
ID: 2011298
What's wrong with the two proposed answers/comments?  Both should work.  I've re-read your question, and according to that, these should work.


0
 

Expert Comment

by:bard081298
ID: 2011299
If I understand what you are asking, you want to rename all of the files at once.  I don't think there's a tool that will do this, but the above 2 answers will certainly result in all of the files being renamed, which is the end result you want anyway.  They just do it one file at a time, which is how a utility that "renames them all at once" would do it under the covers.

Bard
0
 
LVL 1

Expert Comment

by:alextr
ID: 2011300
What is wrong with two above solution? They work fine for your problem. If your problem is different, please explain it better!!
0
 
LVL 84

Expert Comment

by:ozo
ID: 2011301
The only real difference I see between the question and the answers is
ls cs*.bakup*.1999*
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 30 total points
ID: 2011302
according to ozo's comment

ls cs*.bakup*.1999*|awk -F. '{print "mv "$0" /accounts/today/"$1".abc";}'|sh
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 2011303
.. or if you want to have a simple command (alias in csh):

alias mv_all 'ls \!* |awk -F. '"'"'{print "mv "$0" /accounts/today/"$1".abc";}'"'"'|sh'

which is then to be called like:
   mv_all cs*.bakup*.1999*
0
 
LVL 1

Expert Comment

by:arthurd
ID: 2011304
whatever
0
 

Author Comment

by:Papsniper
ID: 2011305
Hi,

Your command worked.I wanted only a single line to be typed at my unix prompt which you had sent.

ls * | awk F. '{print "mv "$0" /accounts/today/"$1".abc";}' |sh

Sorry for the delay as i was away from my work.

Thanks,
Pap.


0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question