Results 1 to 4 of 4
HI,
as part of my college work, I have to create a UNIX command which can rename in the style of the DOS rename. I have the basic code working, ...
- 04-20-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 2
UNIX rename script, DOS Style
HI,
as part of my college work, I have to create a UNIX command which can rename in the style of the DOS rename. I have the basic code working, which will rename the files. But i cant seem to get the file extension, rename bit sorted. I think it might be my regex but not sure, any help would be good. Here is the code i have so far, please ignore the error checking:
any advice would be great on where i might possibly be going wrong.Code:#!/bin/sh # # - A DOS STYLE RENAME # case $# in 0) echo "Usage: dosRename file [ ... ] target" exit ;; #2) echo "dosRename: $file: Can't have anything after target" # exit # ;; '..') echo "dosRename: $file: Can't have more than one dot" exit ;; '**') echo "dosRename: $file: Can't have more than one asterisk" exit ;; #[!-f]) echo "dosRename: $file: Doesn't exist" # exit # ;; 6) echo "dosRename: $file: Must have a dot" exit ;; 7) echo "dosRename: No target" exit ;; *) for file do case $file in [A-Za-z0-9]*\.\*) filePart=name ;; \*\.[A-Za-z0-9]*) filePart=etx ;; esac done endFile=$file fileName=`echo $endFile | sed -e 's/\.\*//'` extension=`echo $endFile | sed -e 's/\*\./\./'` while [ $# -ne 1 ] do case $filePart in 'name') result=`echo $1 | sed -e "s/[A-Za-z0-9]*\.\(.*[A-Za-z0-9]*\)/$fileName\.\1/"` mv $1 $result ;; 'ext') result=`echo $1 |sed -e "s/\.[A-Za-z0-9]*/$extension/"` mv $1 $result ;; esac shift 1 done ;; esac
also i am unable to use python as we have not yet covered it in the course,
thanks guys
- 04-20-2008 #2
Well, first off, this is misspelled:
Secondly, your code seems extremely complicated for this task, and in any event, it is against the forum rules to help with homework assignments. If you can narrow down your question to something specific, we can help you then.Code:filePart=etx
DISTRO=Arch
Registered Linux User #388732
- 04-20-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 2
well thats got it sorted thanks. but its hardly doing my homework as all of the coding is already done.
- 04-20-2008 #4
Except that the coding isn't already done, as it has errors. Whereas the question "I wrote this script, and this particular line isn't working. It's supposed to do this, but instead it's doing this." is a good way to ask about homework.
DISTRO=Arch
Registered Linux User #388732


Reply With Quote