The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Recursion to Copy a Directory structure avrkiran Shell Programming and Scripting 2 03-31-2008 02:43 AM
Copying with directory structure Cnfsed UNIX for Dummies Questions & Answers 4 11-29-2007 12:51 AM
Need help in Directory Structure murtaza Shell Programming and Scripting 5 03-29-2007 11:14 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 04:01 PM
Copying a Directory Structure to a new structure jhansrod UNIX for Dummies Questions & Answers 8 07-27-2005 06:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-10-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
redirection and copying with same directory structure

Dear Experts,

How can I solve this problem ?

I want to redirect with having the same directory structure as in my input.
Code:
for temp in `find ./CSV/ -name  "*.v"` 
do
  fname = `basename $temp`

./script.sh $temp  >  ./out/$fname 
      
done
But my problem here is all the *.v files are processed but get stored in the same directory.

I want to preserve the directory structure when redirecting to out directory here.

Ex-
Input file is inside ./CSV/GSM/ad0_conv.v
then after running the above script
it should be ./out/CSV/GSM/ad0_conv.v

Pls help...
  #2 (permalink)  
Old 12-10-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
Post

Just stop using basename.
If you don't already have the directory structure created in ./out use mkdir -p 'dirname $temp` first.
  #3 (permalink)  
Old 12-10-2007
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
Quote:
Originally Posted by Smiling Dragon View Post
Just stop using basename.
If you don't already have the directory structure created in ./out use mkdir -p 'dirname $temp` first.
Thanks Dragon for the reply and your time..

I did something like below:
Code:
for temp in `find ./CSV/ -name  "*.v"` 
do
   
     mkdir -p out/`dirname $temp` 
   ./transform.sh $temp  >  ./out/$temp
done
But Previously in this forum I found some related to do this like below

Code:
INDIR=./CSV
OUTDIR=./out

#copy only directories with "*cpp" filenames
find $INDIR -type f -name "*.file" -exec dirname {} \; |
  sed -e "s/^\($INDIR\)\(.*\)/$OUTDIR\2/g" | xargs mkdir -p
But I tried to implement xargs to achieve my goal but I am not suceded.
Can I do the same thing what I did in my code with sed and xargs.

Thanks in advance..
  #4 (permalink)  
Old 12-10-2007
Smiling Dragon's Avatar
Smiling Dragon Smiling Dragon is offline Forum Advisor  
Disorganised User
  
 

Join Date: Nov 2007
Location: New Zealand
Posts: 922
You certainly could use xargs but I think that second solution is a little overengineered.
If you are after a simpler commandline, try using the -exec option on find:
find ./CSV/ -name "*.v" -exec mkdir -p out/`dirname {}\;` -exec ./transform.sh {} > ./out/{} \;
(Untested)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0