Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on renaming file extensions.. within the Unix/Linux forums, part of the Operating Systems category; Anyone plz tell me the command to rename file extensions in unix.. That command should be other than: mv sample.txt sample.html...
|
|||||||
|
|||
|
Re: renaming file extensions..
file='/user/abcde1/v/first.txt'
mv $file `echo $file | sed 's/\(.*\.\)txt/\1html/'` I got this command to rename extension and it works correctly. But i don know how it does(the actual functionality). help me out. plz.. |
|
|||
|
Re: renaming file extensions..
That's aweful programming!!!
What that command does is, Code:
mv /user/abcde1/v/first.txt /user/abcde1/v/first.html Code:
file='/user/abcde1/v/first.txt' //Assign the filename to variable file mv $file `echo $file | sed 's/\(.*\.\)txt/\1html/'` Whichever string you give inside backquotes, will be considered a command and executed. So, Code:
`echo $file | sed 's/\(.*\.\)txt/\1html/'` echo $file will print the value of $file into the buffer. Since we are using pipe, sed will act on this data (i.e. the value of $file). sed is an editor. and 's' stands for substitution. It should be simple now to get what the command is doing. But, it is seriously dumb programming if one chooses this command instead of Code:
mv filename.ext filename.newext
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR] Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!" |
|
|||
|
Re: renaming file extensions..
You are most welcome.
I guess you do know about sed. sed is (one of) the best stream editor. It comes in handy in a lot of occassions. To explore the possibilities with sed read this. Sed - An Introduction and Tutorial
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR] Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!" |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Listen to any PDF file!!! | Shivanna | Geeks Lounge | 8 | 4 Weeks Ago 08:19 AM |
| How to store a File in Databes? | chowsys | VB.NET | 2 | 12-26-2007 04:42 AM |
| Can we edit the file | fred | Windows | 1 | 09-13-2006 12:06 PM |
| Is this command serve the purpose of renaming | christia | Unix/Linux | 1 | 09-09-2006 04:18 PM |
| C Programming - File management in C | Lokesh M | C and C++ | 0 | 05-31-2006 03:35 PM |