tr from the command line

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Carl Parrish
Date:  
Subject: tr from the command line
Can't you use regexp with tr? Anyways I found rename. Wish I'd know this
was here b4. For instance did you know that you can change all *.htm to
*.html files like so

rename .htm .html *.htm

So easy. is this a standard *nix tool or just Linux or just RH? Anyone
know?

Carl Parrish

On Tue, 2002-05-14 at 18:39, der.hans wrote:
> Am 14. May, 2002 schwätzte Carl Parrish so:
>
> > I've got a lot of files called *_log. I want to change them all to
> > *.log. I *think* I want to use the tr command. Can anyone give me the
> > syntax? my undertanding from the info and man files isn't working.
>
> The problem with tr is that it will change every occurance, e.g.
>
> $ echo fred_vuz_hier_log | tr _ .
> fred.vuz.hier.log
>
> What you need is something that either turns _log into .log or at least
> recognizes that the _ is right before log, which is the end of the string.
>
> $ for i in 1 2 3 4 5 6; do touch /tmp/fred/${i}_log; done
> $ ls /tmp/fred
> 1_log 2_log 3_log 4_log 5_log 6_log
> $ for i in /tmp/fred/*_log; do mv $i ${i%_log}.log; done
> $ ls /tmp/fred
> 1.log 2.log 3.log 4.log 5.log 6.log
>
> '%' tells bash to knock that string off the end if it exists.
>
> Use '#' to whack something off the beginning.
>
> $ for i in /tmp/fred/6*; do dir=`dirname $i`; log=`basename $i`; mv $i
> $dir/six${log#6}; done
> $ ls /tmp/fred
> 1.log 2.log 3.log 4.log 5.log six.log
>
> ciao,
>
> der.hans
> --
> # https://www.LuftHans.com/
> # Motorraeder toeten nicht. Motorraeder werden getoetet.
>
> ________________________________________________
> See http://PLUG.phoenix.az.us/navigator-mail.shtml if your mail doesn't post to the list quickly and you use Netscape to write mail.
>
> PLUG-discuss mailing list -
> http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss