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
rename a lot of files again ajp7701 Shell Programming and Scripting 11 03-31-2008 07:36 PM
rename files help piltrafa UNIX for Dummies Questions & Answers 2 10-04-2007 09:47 AM
How to Read config (.cfg) files using shell scripting smallwonder UNIX for Advanced & Expert Users 5 03-02-2007 12:37 AM
rename files mpang_ Shell Programming and Scripting 2 11-01-2006 01:17 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 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 07-04-2006
gfhgfnhhn gfhgfnhhn is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 77
Exclamation rename files using shell scripting

Hi all,

i want to rename some files in my directory
using korn shell scripting.

1) i want to rename files who have no extension so that they
will have the format: filename.extension

and

2) i want the files who has extension initially, to stay the same
(they will not be changed)

do you have any idea about how to do this using ksh scripting?
(without using sed or awk)

with regards
  #2 (permalink)  
Old 07-04-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
not ksh but works fine

$ cd where you want
$ find -maxdepth 1 -type f -regex "^.*/[^\.]*$" -exec mv {} {}.extension \;
  #3 (permalink)  
Old 07-04-2006
gfhgfnhhn gfhgfnhhn is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 77
Exclamation

thank you very much
but i still need the ksh solution,
because i also want to do some operation on the files
other than renaming them.
i want to pass the "filenames with no extension" to a ksh variable
do some operation (including rename)

for example:
i have code to process files which have format like: filename.ext

for file in *.ext; do
#some commands
done

but i want to modify the code lines above as to
process files which have no extension (format like: filename ), while the files which have name format like filename.ext will not be affected
  #4 (permalink)  
Old 07-04-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
You can use
for file in `find ...` (without -exec)

But you'll have problems with files with spaces, see spaces in filenames
  #5 (permalink)  
Old 07-04-2006
Hitori's Avatar
Hitori Hitori is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2006
Posts: 360
Code:
#!/bin/sh

find -maxdepth 1 -type f -regex "^.*/[^\.]*$" | while IFS= read vo
do
mv "$vo" "$vo".ext
other commands
done
Try #!/bin/ksh
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 01:16 AM.


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