Run SED for all index.jsp files across a directory structure.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Run SED for all index.jsp files across a directory structure.
# 1  
Old 09-13-2010
Run SED for all index.jsp files across a directory structure.

Hi,
I am a novice and require help once again.

I have a over 200 file all called index.jsp placed in different directories

The following Sed command gives me the data of all included jsp files in index.jsp

Code:
sed -n -e 's/^.*page="\([^"]*\).*$/\1/p' index.jsp

How can I run the above command for all the index files and get an output that has the following

1.name of the entire path where index.jsp file is and
2.Result of the above sed command.

Help!!

Last edited by Scott; 09-13-2010 at 11:51 AM.. Reason: Code tags
# 2  
Old 09-14-2010
Code:
source=/XXX/XXX
cd $source

for file $(find . -name index.jsp -type f)
do
  DIR=$(dirname $file)    # rule 1. DIR is the file's path.
  sed -n -e 's/^.*page="\([^"]*\).*$/\1/p' $file  # rule 2 
  # do something
done

# 3  
Old 09-14-2010
Hi,
Sir the problem is Assigning source. The code will work for only one directory, but I want it to look into all subdirectories automatically.

Thanks for help
# 4  
Old 09-14-2010
try like this
Code:
for file in $(find -name "index.jsp") ; do 
  echo -e "File is -> $file\nThe result is sed output ->\n`sed -n -e 's/^.*page="\([^"]*\).*$/\1/p' $file`" 
done

# 5  
Old 09-14-2010
You mentioned different directories but were not clear how they were related. The following assumes that all the directories are located under the current working directory, ".".

Code:
find . -name index.jsp -print -exec sed -n -e 's/^.*page="\([^"]*\).*$/\1/p' '{}' \;

Regards,
Alister
# 6  
Old 09-14-2010
Quote:
Originally Posted by rajkdutta
Hi,
Sir the problem is Assigning source. The code will work for only one directory, but I want it to look into all subdirectories automatically.

Thanks for help
Code:
find . -name index.jsp -type f

Not understand your problem.

Above command DO find out all index.jsp files in any subfolders from current folder.

If you need find the file in different folders (not subfolders), you can try

Code:
find /folder1 /folder2 /folder3 -name index.jsp -type f

# 7  
Old 09-14-2010
Hi,
Sorry for my explaination.
Scenario is as follows:
1. There is a Directory XYZ with many subdirectories in it which in turn have many sub-sub directories.
2. These Directories and sub directories have many *.jsp files
3. These jsp files have many include files

I want a list as follows

Col1 Col2 Col3 Col4
jsp filename full path name name of include file path of include file

When i use "find " I get the entire directory str,
When i use find with sed I get Col4&Col3
I am unable to get Col 1 & 2

Please Help
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Archiving files keeping the same structure directory

Hello Team, We would like to backup a lot of files inside of a structure of directories, four, five or more levels in some Ubuntu, Mac and Solaris systems. For instance: /home/chuck/sales/virgin/rent-quote.pdf /home/chuck/sales/marriott/vacation-quote.pdf... (2 Replies)
Discussion started by: csierra
2 Replies

2. Shell Programming and Scripting

Extract files from tar ball without directory structure

Hi, I have tar filw which has multiple directories which contain files. When i extract using tar -xf the directory structure also get extracted. I require only files and not directory structures as there will be overhead of moving the files again. So i searched here and got a solution but... (4 Replies)
Discussion started by: chetan.c
4 Replies

3. Shell Programming and Scripting

How to traverse directory structure and sum size of files?

How do I write a bash or ruby or perl or groovy script to print all the files in my directory tree that are one-to-two years old, the size of each file, and the sum of file sizes and then delete them? I was using find . -atime +365 -exec rm '{}' \; but the problem was that I could not... (5 Replies)
Discussion started by: siegfried
5 Replies

4. Shell Programming and Scripting

Copying a directory structure with the latest versions of files

Hello I have three directory structures for code releases. Each directory structure looks like this: bash-3.00$ ls -R | more .: Test_Release_1 Test_Release_2 Test_Release_3 ./Test_Release_1/dbcode: rp_online_import_srdp.pkb-1 srdp_ar_validation.pkb-1... (1 Reply)
Discussion started by: Glyn_Mo
1 Replies

5. Shell Programming and Scripting

Script to run a command on all txt files present in a dir structure

Hi, I have a directory structure like the one given below root\a\b1 root\a\b2 root\b\b1 root\b\b2 . . . root\j\b1 root\j\b2 Now, there are a txt files in each dir and subdir, there is a root.txt I have to write a script where in i have to run a command called "genrb <filename>"... (6 Replies)
Discussion started by: vikramsinghnegi
6 Replies

6. SCO

Transfer files wih directory structure.

I need to transfer software off a SCO OpenServer 5.0.5 server. I can not seem to read this server's tape on my other server since the tape drive (IBM Gen 5 DAT 72GB) will continuosly "eject" this DAT 8 tape. I have been able to 'tarball' most of the smaller directories with success and... (11 Replies)
Discussion started by: uxlunatick
11 Replies

7. UNIX for Dummies Questions & Answers

copy files with directory structure

i have a text file as. /database/sp/NTR_Update_Imsi_List.sql /database/sp/NTR_Update_Imsi_Range_List.sql /database/sp/NTR_Vlr_Upload.sql /database/tables/StatsTables.sql /mib/ntr.mib /mib/ntr.v2.mib /scripts/operations/ntr/IMSITracer.ph /scripts/operations/ntr/IMSITracer.pl ... (3 Replies)
Discussion started by: adddy
3 Replies

8. UNIX for Advanced & Expert Users

MV files from one directory structure(multiple level) to other directory structure

Hi, I am trying to write a script that will move all the files from source directory structure(multiple levels might exist) to destination directory structure. If a sub folder is source doesnot exist in destination then I have to skip and goto next level. I also need to delete the files in... (4 Replies)
Discussion started by: srmadab
4 Replies

9. Shell Programming and Scripting

disk space used for files with in a directory structure.

Hello, I am new to shell scripting and would really appreciate if someone could help me with this question. I have a directory structure as follows.. main directory is DATA under which i have different directories names fileserver01, fileserver02 ... till fileserver 15. under each... (8 Replies)
Discussion started by: kasala
8 Replies
Login or Register to Ask a Question