Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Linux and Unix
Tag Cloud
access audio black screen blue screen boot bsod connection crash dell desktop drivers dvd email error excel firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor recovery registry cleaner router screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
substring filenames

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
cgjoker's Avatar
Senior Member with 205 posts.
 
Join Date: Aug 2003
11-Sep-2003, 04:57 PM #1
substring filenames
I would like to substring a bunch of files that would have various names but would always end with .dct.

For example...

file1.dct
file2.dct
dog1.dct
cat1.dct

I would like to rename them all to

file1
file2
dog1
cat1

These filenames would always change though so I wouldn't be able to just do a mv.

Here is some code that I would need to incorporate into the substring function.

for DCT1 in `ls`;

do
cp $DCT1 $DCT1.dat
done
codejockey's Avatar
Senior Member with 1,410 posts.
 
Join Date: Feb 2002
12-Sep-2003, 02:48 AM #2
How about something like this:

Code:
#!/bin/bash
for FILE in `ls`
do
    NEWFILE=`echo $FILE | sed 's/\.dct//'`
    cp $FILE $NEWFILE
done
This is only one approach, and doesn't consider any error cases (what if the file is a directory, for example?) but the code should give you the basic idea.

Hope this helps.
Closed Thread Bookmark and Share

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Smart Search

Find your solution!



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.

Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 09:10 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.