Anyone plz tell me the command to rename file extensions in unix..
That command should be other than:
mv sample.txt sample.html
Anyone plz tell me the command to rename file extensions in unix..
That command should be other than:
mv sample.txt sample.html
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..
That's aweful programming!!!
What that command does is,
Here's how it works.Code:mv /user/abcde1/v/first.txt /user/abcde1/v/first.html
$file will have the value /user/abcde1/v/first.txt.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,is considered as a command.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. Why would you want to get into this complication?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!"
Thank you.
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!"
Thats so useful. thanks a lot.