Fedora Linux Support Community & Resources Center
  #1  
Old 18th April 2006, 08:59 PM
thesource Offline
Registered User
 
Join Date: Mar 2005
Posts: 83
Question Scripting help

hello all-

I need some help writing a script.

I would like to script to

1. perform a search for file name with exension
2. rename the folder two levels up with the file name found


example

for file in (find -name *.cat ); do
mv .. $filename.

The only problem is that the output of the find wants to name the .. folder the whole path of *.cat

example

\dirone\dirtwo\myfile.cat

How do I tell it to only use "myfile.cat" to rename the granpa directory .. ?

Can I use sed to extract myfile.cat and pipe that output into another command?


confused here?
Reply With Quote
  #2  
Old 18th April 2006, 09:49 PM
ezzetabi Offline
Registered User
 
Join Date: Mar 2006
Location: assert(false);
Posts: 111
do not try it as root...
Code:
#!/bin/bash
AF="$PWD"
FOLDER=~
EXT=cat
A=`find "$FOLDER" -iname '*.'"$EXT"`
IFS=$'\n'
for i in $A
do
  DIRNAME=`dirname "$i"` #dirname of the file
  FILENAME=`basename "$i"` #filename and dest of renaming
  cd "$DIRNAME"/../..
  CF=`dirname "$PWD"` #folder that keeps the folder we'll rename

  mv "$PWD" "$CF"/"$FILENAME" #renaming
done

cd "$AF"

Last edited by ezzetabi; 18th April 2006 at 09:51 PM.
Reply With Quote
  #3  
Old 18th April 2006, 10:40 PM
Firewing1 Offline
Registered User
 
Join Date: Dec 2004
Location: Canada
Age: 23
Posts: 9,224
Code:
ls -l | awk '{printf $9"\n"}' | grep \.ext$
will list all files ending in ext... Does that help?
Firewing1
__________________
[+] My open source software and blog
[+] Some of my howtos: (for full list, click here)
Reply With Quote
Reply

Tags
scripting

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting help boknoy Using Fedora 3 3rd August 2007 02:44 PM
Scripting Help! KoubaK Linux Chat 2 28th April 2007 05:45 AM
help with scripting mitchell2345 Using Fedora 2 28th February 2007 01:08 AM
Scripting help mitchell2345 Using Fedora 5 23rd January 2007 07:06 AM
cron scripting/bash scripting coolbeansdude51 Using Fedora 7 16th January 2007 03:13 AM


Current GMT-time: 15:58 (Friday, 25-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat