There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu graphics hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry repair router security slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
substring filenames

Reply  
Thread Tools
cgjoker's Avatar
Member with 205 posts.
 
Join Date: Aug 2003
11-Sep-2003, 05: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, 03: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.
Reply

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:59 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.