The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
read list of filenames from text file and remove these files in multiple directories fxvisions Shell Programming and Scripting 5 08-07-2008 03:59 PM
read list of filenames from text file, archive, and remove fxvisions Shell Programming and Scripting 5 03-20-2007 09:56 PM
Getting emials with SUSPECT: Prefix akrathi UNIX for Dummies Questions & Answers 1 02-21-2006 03:11 PM
How to cut prefix from a string? nir_s Shell Programming and Scripting 2 02-19-2006 04:16 PM
remove filename prefix peter.herlihy UNIX for Dummies Questions & Answers 2 07-11-2002 01:08 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-25-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Question Remove prefix from filenames

I'm trying to put together a shell script that will append specific prefixes based on the content of filenames. I think I have this part down. However, I want to append before that part a process that will remove the current prefix before it renames the files with the new prefix.

For example, if all the files I want to rename, for example are:
---
ALPHANUM.ABCDEFG
ALPHANUM.HIJKLMNOP
ALPHANUM.QRSTUV
ALPHANUM.WXYZ
ALPHANUM.01234567890
---
and depending on the contents, if $[0-9] append the prefix "NUM." and $[A-Z] append prefix "ALPHA". The part where I'm stuck at is trying to figure out how to remove the "ALPHANUM." prefix before I do any appending.

Tried searching through the forums with "remove suffix, change suffix, remove prefix, change prefix," and "prefix" to get some examples, but did not spot anything I'm trying to do.

Please help.

Thanks!
  #2 (permalink)  
Old 01-25-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,116
With ksh:
$ filename=ALPHANUM.abc
$ echo ${filename#ALPHANUM\.}
abc
$
  #3 (permalink)  
Old 01-25-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Question

Thank you. I would like to use the bash shell though. Is there a website containing the differences between the shells, and specify which variable / command relates to the other, etc.? Also, the files I am actually working with to rename contains both alpha and numeric characters. How do I specify that the one common perfix for all the files are removed? (Using the bash shell.) Thanks!
  #4 (permalink)  
Old 01-25-2006
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
Registered User
  
 

Join Date: May 2002
Location: India
Posts: 295
Hi Lee,

I tried this snipped to identify if the file name extension has numeric character. let me know if this snippet ring any bells.

echo "${an}"| nawk '{
if ( $0 ~ /[0-9]/ )
{
printf("%s is num\n", $0);
}
else
printf("%s is alpha\n", $0);
}
'
  #5 (permalink)  
Old 01-25-2006
HLee1981 HLee1981 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 35
Quote:
Originally Posted by linuxpenguin
I tried this snipped to identify if the file name extension has numeric character. let me know if this snippet ring any bells.
'
Hi. Thanks for your help. I should've mentioned that the string of text after the ALPHANUM phrase are not extensions. They have their own extensions actually, like .txt. Sorry for not specifying this before.
  #6 (permalink)  
Old 01-25-2006
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
Registered User
  
 

Join Date: May 2002
Location: India
Posts: 295
well, they may not be extensions but they are .*, right? so as long as they are .* the above should still work
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0