1826399 Members
4141 Online
109692 Solutions
New Discussion

Re: tr question

 
SOLVED
Go to solution
Andrej Vavro
Frequent Advisor

tr question

Hi,

I need to rename file from
/app/abd/12345.w55 to
/app/abd/12345.p55 in script.

echo ${file1} | tr 'w' 'p' is giving me
/ap/abd/12345.p55

It deletes one 'p'. It's in bash on SuSE SLES7.
I am talking about thousand files. Just change extension from w to p.

Thanks for your help in advance.
Andrej
5 REPLIES 5
Andrej Vavro
Frequent Advisor

Re: tr question

Sorry, it's

tr -s 'w' 'p'
Umapathy S
Honored Contributor

Re: tr question

Andrej,
Your question itself contains the solution.

tr -s actually squeeze and repeats. Leave the -s option to get your requirement. Check man tr.


-s, --squeeze-repeats
replace each input sequence of a repeated character that is
listed in SET1 with a single occurrence of that character


HTH,
Umapathy

Arise Awake and Stop NOT till the goal is Reached!
Jean-Luc Oudart
Honored Contributor
Solution

Re: tr question

assuming that's all the files are *.w*

for fln in `ls *.w??`
> do
> newfln=`echo $fln | sed -e 's/\.w/\.p/'`
> mv $fln $newfln
> done

Rgds,
JL
fiat lux
Sergejs Svitnevs
Honored Contributor

Re: tr question

change script to use "sed" instead of "tr":

echo ${file1} | |sed 's/\.w/\.p/'

Regards,
Sergejs
Stuart Browne
Honored Contributor

Re: tr question

Or you could just use bash buildins..

for FILE in /path/to/*.w??
do
mv $FILE ${FILE//\.w/\.p}
done

go bash ;) Much fun.
One long-haired git at your service...