Results 1 to 7 of 7
Hey!
I am new to this forum but confused in programming to Bash scripting. How do change the file extension using awk and expr (or egrep).
Ex: me.mp3 to me.wav
...
- 10-19-2007 #1Just Joined!
- Join Date
- Oct 2007
- Posts
- 4
Question about text manipulation (substitution) using expr/egrep/awk in Bash
Hey!
I am new to this forum but confused in programming to Bash scripting. How do change the file extension using awk and expr (or egrep).
Ex: me.mp3 to me.wav
I have tried:
files=$(ls -1 | grep *.mp3)
for x in $files
do
mv $x band_song$x
done
This example only changes the file name and not the extention.
- 10-19-2007 #2Just Joined!
- Join Date
- Oct 2007
- Posts
- 37
You could do something like:
for i in `ls -1 *.mp3| awk -F. '{print $1}'`; do mv $i.mp3 $i.wav; done
Of course there are a million other ways and probably better ones too, but this way works also.
- 10-19-2007 #3Just Joined!
- Join Date
- Oct 2007
- Posts
- 4
Text manipulation (substitution) using expr/egrep/awk in Bash

I want to use expr in order to change a the file extension from .mp3 to .wav. I wasn't able to find any examples in Google.
I know the more simple codes are a lot better than complex codes.
- 10-19-2007 #4
Why expr?
A few ways (without expr, awk etc.):
Code:$ touch {1..5}.mp3 $ ls 1.mp3 2.mp3 3.mp3 4.mp3 5.mp3 $ rename s/.mp3/.wav/ *mp3 $ ls 1.wav 2.wav 3.wav 4.wav 5.wavWith zsh:Code:$ ls 1.mp3 2.mp3 3.mp3 4.mp3 5.mp3 $ for f in *.mp3;do mv "$f" "${f%.*}".wav;done $ ls 1.wav 2.wav 3.wav 4.wav 5.wav
Code:% ls 1.mp3 2.mp3 3.mp3 4.mp3 5.mp3 % autoload -U zmv % zmv -W '*.mp3' '*.wav' % ls 1.wav 2.wav 3.wav 4.wav 5.wav
- 10-19-2007 #5Just Joined!
- Join Date
- Oct 2007
- Posts
- 4
I have this code:
#!/bin/bash
#
# Replaces blanks with underscores in all the filenames
# of the current directory.
i=0
for filename in *
do
echo "$filename" | grep -q " "
if [ $? -eq 0 ]
then
fname=$filename
n=`echo $fname | sed -e "s/ /_/g"`
mv "$fname" "$n"
((i++1))
fi
done
echo "$i file(s), done."
exit 0
When I tried to substitute my information, it didn't compute.
- 10-20-2007 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
- 10-20-2007 #7


Reply With Quote
