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
How to get file extension shirleyeow Shell Programming and Scripting 17 01-17-2008 08:40 AM
extension problem please help sharmasdeepti UNIX for Dummies Questions & Answers 1 10-24-2007 07:29 AM
without extension adurga UNIX for Dummies Questions & Answers 3 07-02-2007 12:34 PM
Changing userID and Changing group and GID deal732 Shell Programming and Scripting 2 04-18-2007 10:09 AM
Lynx - Downloading - extension handling - changing mime type? yitzle UNIX for Dummies Questions & Answers 2 10-17-2006 11:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-30-2007
mohan705 mohan705 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
Changing extension

Hi ,
I need to replace the file name extension with txt to csv,i wrote the below script when executing its giving the below error.Please anyone how to do this?


$ a2.sh
mv: *.: cannot access: No such file or directory
./a2.sh[7]: o: bad number
$ vi a2.sh

a2.sh
-----
#!/bin/ksh
txt=$1
csv=$2
for file in *.$txt ; do
mv $file ${file%$txt}$csv
done
exit o


Thanks ,
Mohan
  #2 (permalink)  
Old 06-30-2007
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
ur script looks wrong...
for loop expects a list for action.
"for file in *.$txt" means what???
if u are providing list as the 1st argument ( as u wrote in ur code) than why u are not supplying list when executing the script.

if u want to do with all the file in the current dir use
for file in `/bin/ls *.txt`

and if as an argument, use for file in $*

correct me anyone if i m wrong...
  #3 (permalink)  
Old 06-30-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
If you want to rename all the '*.txt' files to '*.csv' :
Code:
for file in $(ls *.txt 2>/dev/null)
do
   mv $file ${file%.txt}.csv
done
The error './a2.sh[7]: o: bad number' comes from your exit statement.
Replace the 'o' by '0'.
  #4 (permalink)  
Old 06-30-2007
mohan705 mohan705 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 134
HI,

Thanks,this is waht i am looking for


Thanks,
Mohan
  #5 (permalink)  
Old 06-30-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Quote:
Originally Posted by mohan705 View Post
I need to replace the file name extension with txt to csv
[...]
With zsh:

Code:
autoload -U zmv
zmv -W '*.txt' '*.csv'
Or if you have rename:

Code:
rename .txt .csv *.txt
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 11:12 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