Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using egrep and mv 1

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I would like to move files from one directory to another keeping dates, owner etc and based on a search pattern.

With the command below I can COPY files as I want:

Code:
cd $dir ; find . -print | egrep -v '$pat' | cpio -pdvmu $outdir
[\code]

What is the equivalent command to move the files and not copy?

Many thanks!
 
try
Code:
find . -name "$pat" -exec mv {} $outdir \;

Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.
 
Thanks a lot, however the pattern does not seem to work the same with -name of find.

For instance with egrep I have
$pat = "\\.tod|\\.tod_glb|\\.sgy|\\.segy|\\.gbs|\\.ash|\\.gsr|\\.psh|\\.shf|\\.psp|\\.tsp|\\.asp|\\.sess|\\.hts|\\.hzd|\\.2cl|\\.cdf|\\.cdf|\\.zgf|\\.asc|\\.ZGF|\\.dts|\\.mcf|\\.zcm|\\.ptf|\\.mf|\\.inp|\\.tmpcgm|\\.lst|\\.log|\\.w1|\\.hzbf|\\.w2|\\.w3|\\.core|\\.tmp|\\zap3workfile|\\tmpcgm|\\hzbf\\." as I want to exclude all files with those extensions.
 
Hmmm I didn't look closely enough at your original problem

You could try
Code:
for file in `find . -print`
do
  case $file in
    *.tod|*.tod_glg) ;;
    *) mv $file outdir;;
  esac
done
I've only put in a couple of patterns but you get the idea.
I'm sure some of the gurus out there will provide a more elegant solution

Columb Healy
Living with a seeker after the truth is infinitely preferable to living with one who thinks they've found it.
 
thanks but there should be a way to do this in one line surely..
 
Something like this ?
cd $dir ; find . -print | egrep -v '$pat' | tee /tmp/$$ | cpio -pdvmu $outdir && rm -f $(</tmp/$$)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV but I am getting an error:can't read "(</tmp/$$)": no such variable

What's /tmp/$$ for?
 
Maybe something like this ?
cd $dir ; find . -type f -print | egrep -v "$pat" | tee /tmp/$$ | cpio -pdvmu $outdir && rm -f `cat /tmp/$$`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top