read files from subdirectories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers read files from subdirectories
# 1  
Old 10-12-2008
read files from subdirectories

hello there

the problem i got: i need to list .rrd files in each sub-directory from the parent directory, then create .xml files for each rrd files, the xml file should be in the same subdirectoryas rrd file.


i have tried
ls |awk '{print "/gpfs/grid/software/rrdtool/rrdtool-1.2.26/src/rrdtool dump " $1 " ./" $1".xml"}' |sh
and it is working if i cd into specific sub-directory

but i have many many sub-directories, i tried
ls -R |awk '{print "/gpfs/grid/software/rrdtool/rrdtool-1.2.26/src/rrdtool dump " $1 " ./" $1".xml"}' |sh
it is not working, because this script doesn't "step into" each sub-directory


could anyone help with this?
many thanks
# 2  
Old 10-12-2008
Code:
rrdtool="/gpfs/grid/software/rrdtool/rrdtool-1.2.26/src/rrdtool"
export rrdtool

find . -name '*.rrd' -exec sh -c '
  f="$1" 
  "$rrdtool" dump "$f" "${f%rrd}"xml
  ' inline {} \;

# 3  
Old 10-12-2008
Quote:
Originally Posted by radoulov
Code:
rrdtool="/gpfs/grid/software/rrdtool/rrdtool-1.2.26/src/rrdtool"
export rrdtool
 
find . -name '*.rrd' -exec sh -c '
  f="$1" 
  "$rrdtool" dump "$f" "${f%rrd}"xml
  ' inline {} \;


thank you so much, now it works well.

do you think it is possible to put the xml in the new place, say /user/data/ because the rrd files in each sub-directory may have same name, like dirA have a.rrd, b.rrd dirB have a.rrd b.rrd now i want to creat new 2 set of xml files into /user/data/ that is......is it possible i create dirA and dirB automatically under /user/data/ and have itself a.xml b.xml by using the same script?? which name of commands i might use???


thank you again for your kind help SmilieSmilie
# 4  
Old 10-13-2008
Under /user/data or under user/data?
The below code creates the directory structure user/data/... under your current directory.

Code:
rrdtool="/gpfs/grid/software/rrdtool/rrdtool-1.2.26/src/rrdtool"
dest="user/data"
export rrdtool dest

find . -name '*.rrd' -exec sh -c '
  f="$1" p="${f%/*}" n="${f##*/}"
  mkdir -p "$dest/$p"
  "$rrdtool" dump "$f" "$dest/$p/${n%rrd}xml"
  ' inline {} \;

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

2. Shell Programming and Scripting

Unzip all the files with subdirectories present and append a part of string from the main .zip files

Hi frnds, My requirement is I have a zip file with name say eg: test_ABC_UH_ccde2a_awdeaea_20150422.zip within that there are subdirectories on each directory we again have .zip files and in that we have files like mama20150422.gz and so on. Iam in need of a bash script so that it unzips... (0 Replies)
Discussion started by: Ravi Kishore
0 Replies

3. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

4. Shell Programming and Scripting

scp files from subdirectories only.

Hi there, Our current directory structure is set up as follows: -2013-09-20 - 380134664407418202 - 76523.html - 5331257754517660 - 76267.html - 76268.html - 76269.html - 76270.html - 76271.html - 76272.html - 76273.html - 76274.html -... (2 Replies)
Discussion started by: jimbojames
2 Replies

5. UNIX for Dummies Questions & Answers

search for files in subdirectories

Hi! I want to find files located in subdirectories. I have tried ls -R | grep myfile but this won't tell me where the file is, only that it is there. Any one have a better idea? Thanks, --Euclid (3 Replies)
Discussion started by: euclid3628800
3 Replies

6. UNIX for Dummies Questions & Answers

list the files but exclude the files in subdirectories

If I execute the command "ls -l /export/home/abcde/dev/proj/code/* | awk -F' ' '{print $9}' | cut -d'/' -f6-8" it will list all the files in /export/home/abcde/dev/proj/code/ directory as well as the files in subdirectories also proj/code/test.sh proj/code/test1.c proj/code/unix... (8 Replies)
Discussion started by: shyjuezy
8 Replies

7. UNIX for Dummies Questions & Answers

Listing all files in all subdirectories

From the main directory, I have multiple layers of subdirectories and imbedded files (jpg's) that I would like to have a quiklook. Is there a way of listing out the contents of all of the subdirectories and files with a one-line command? Thx... (3 Replies)
Discussion started by: kuciauskas
3 Replies

8. Shell Programming and Scripting

Problem with changing directory and subdirectories to read only

I have a directory with its subdirectories and files. I want to change them all to read only. Say it is ~/test chmod -R 444 ~/test chmod: `/home/myname/test': permission denied I do not understand. Do I have to have executable mode for a diirectory to access. How can I change ~/test to... (5 Replies)
Discussion started by: lalelle
5 Replies

9. Shell Programming and Scripting

copy certain files from subdirectories

Hi all, I'd very grateful for some help with the following. I have a variable number of subdirectories each of which contain a uniquely names results file of the form Results*.dat. I would like to search through all subdirectories and copy out these results file to another directory so that... (3 Replies)
Discussion started by: iomaire
3 Replies

10. UNIX for Dummies Questions & Answers

Searching files within subdirectories

I need to concatenate files that are inside a directory and subdirectories. Those files end with .c Can anyone help me I am using comand 9find) and (cat) but they don't work together.:confused: (1 Reply)
Discussion started by: jalvarez
1 Replies
Login or Register to Ask a Question