?
Solved

rename files in UNIX

Posted on 2007-10-06
6
Medium Priority
?
1,925 Views
Last Modified: 2012-06-21
$ ls

abd_a.dbf  abd_b.dbf  abd_c.dbf  abd_x.dbf


I have to remove "abd_a"  prefix from these files on Unix(AIX) platform

I have like 300+ files and I have to rename these files to normal( REMOVE THE "abd_"  extension)
0
Comment
Question by:ballioballi
  • 4
  • 2
6 Comments
 

Author Comment

by:ballioballi
ID: 20027428
sorry remove "abd_"  only .

so the files will look like a.dbf   b.dbf  x.dbf
0
 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 total points
ID: 20027438
Hi,

for file in *.dbf
do
name=`echo $file | awk -F"_" '{print $2}'`
mv $file $name
done
0
 

Author Comment

by:ballioballi
ID: 20028127
It is perfect and your help is well in time.

If you can add what is $2 or some link to study will be great.

Thanks,
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 

Author Comment

by:ballioballi
ID: 20028138
if it is not "_"

say for example:-

ABDa.dbf  ABDb.dbf  ABDc.dbf  ABDx.dbf

And I need the result as follows:-

a.dbf   b.dbf   c.dbf  x.dbf

How can I do that??

Thanks again for your timely help



0
 
LVL 40

Expert Comment

by:omarfarid
ID: 20028144
Hi,

Ok, I have used awk and specified "_" as filed separator. So $1 is field 1 and $2 is field 2.

In your other example there is no char that can be considered a filed separator, so my script will not work.

You may need to use cut in this case.

For more help see man cut

And for awk man awk
0
 

Author Comment

by:ballioballi
ID: 20028648
Thanks a lot.
I got you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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 …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month5 days, 7 hours left to enroll

601 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