rbp@investor.pgh.pa.us (Bob Peirce #305) (05/25/90)
In article <1990May21.011549.8072@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <207@taumetCOM>, steve@taumetCOM (Stephen Clamage) writes: >|> I don't get it. Why not just: >|> >|> cp source_directory/foo.* target_directory >|> >|> Does your script do something the obvious command doesn't do? > > This does not do what the original poster asked. The poster asked: if >she has a bunch of filenames with the same basename, e.g. foo.a, foo.b, >foo.c, foo.d, etc., how would she go about renaming them all to bar.a, >bar.b, bar.c, bar.d, etc. > Here is a start to getting there. Somebody posted a rename script a while back that does suffixes; eg, rename *.foo to *.bar. I suspect it could be modified to do the above. Here is the script -- #!/bin/csh # script to change suffixes enmasse if ( $#argv != 2 ) then echo "usage: rename from to" exit endif foreach i ( *.$argv[1] ) mv $i $i:r.$argv[2] end -- Bob Peirce, Pittsburgh, PA 412-471-5320 ...!uunet!pitt!investor!rbp rbp@investor.pgh.pa.us
chen@digital.sps.mot.com (Jinfu Chen) (05/26/90)
>cp foo.c bar.c >cp foo.o bar.o I would like to know the answer too, since I can do this in HP/Apollo's Aegis shell in one line: cpf foo{?*} bar@1 -nq I have yet to find a way in csh or bsh to do this simple task. -- Jinfu Chen (602)898-5338 | Motorola, Inc. SPS Mesa, AZ | ...uunet!motsps!digital!chen | chen@digital.sps.mot.com |
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (05/26/90)
In article <16512@phoenix.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul John Falstad) writes: : In article <23368@adm.BRL.MIL> rose@baby.swmed.utexas.edu (Rose Oguz) writes: : >The original files have the same root name and different extensions. How : >can I copy them to files with another root name while keeping the : >extensions? : : There is an easy way, but unfortunately it involves a csh script. Well, not necessarily. On our system it happens you can just say copy 's/foo/bar/' foo.* The copy script is just like the Perl rename script mentioned a while back: #!/usr/bin/perl $op = shift; for (@ARGV) { $was = $_; eval $op; die $@ if $@; system "cp $was $_" unless $was eq $_; } Perlophobes could probably whip one up in some other language. Or more likely, some unholy combination of languages... :-) Larry Wall lwall@jpl-devvax.jpl.nasa.gov
ekrell@ulysses.att.com (Eduardo Krell) (05/26/90)
In article <4a9c480e.12c9a@digital.sps.mot.com> chen@digital.sps.mot.com (Jinfu Chen) writes: >I have yet to find a way in csh or bsh to do this simple task. How about ksh? function cpm { for f in ${1}.*; do cp $f $2${f#${f%.*}}; done } Then all you have to say is "cpm foo bar". Eduardo Krell AT&T Bell Laboratories, Murray Hill, NJ UUCP: {att,decvax,ucbvax}!ulysses!ekrell Internet: ekrell@ulysses.att.com
ooms@delgeo.UUCP (Frank Ooms) (05/28/90)
In article <4a9c480e.12c9a@digital.sps.mot.com> chen@digital.sps.mot.com (Jinfu Chen) writes: >I have yet to find a way in csh or bsh to do this simple task. How about : foreach f (foo.*) cp $f bar.$f:e end -- /* Frank Ooms, (31)15-621554 * * -- * * ..!hp4nl!delgeo!ooms */
ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (06/02/90)
In article <4a9c480e.12c9a@digital.sps.mot.com> chen@digital.sps.mot.com (Jinfu Chen) writes: >I have yet to find a way in csh or bsh to do this simple task. #!/bin/sh # change "FromPattern" "ToPattern" File... # see sed(1) for an explanation of patterns From="$1" shift To="$1" shift for File do mv "$File" "`echo "$File" | sed -e "s/$From/$To/"`" done exit -- "A 7th class of programs, correct in every way, is believed to exist by a few computer scientists. However, no example could be found to include here."