Grep with parent folder


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep with parent folder
# 8  
Old 07-11-2012
Try this:
Code:
find /Volumes/main_HD/Users/omarkn/Sites/chello\ uppd_G5 -type f -name "*_i*" | sed 's/\/[^/]*$//'

# 9  
Old 07-11-2012
Just shell?
Code:
for i in $PWD/*_i* ; do echo "$i"; done

Code:
for i in $PWD/*_i*
do 
  echo "$i"
done

Code:
printf "%s\n" $PWD/*_i*

although you would need to test for when there are no files present with that pattern

Last edited by Scrutinizer; 07-11-2012 at 06:32 AM..
# 10  
Old 07-11-2012
Thank you guys! and thank you Balajesuri!

Actually the funny thing is that:
Code:
find /absolute path/ -type f -name *_i*

is quite sufficient and results in:
Code:
/Volumes/main_HD/Users/omarkn/Sites/chu/o/mhmd_i.html
... and all the rest of files...

but if one adds
Code:
 | sed 's/\/[^/]*$//'

then the actual files are not displayed:

Code:
/Volumes/main_HD/Users/omarkn/Sites/chu/n
/Volumes/main_HD/Users/omarkn/Sites/chu/naw
/Volumes/main_HD/Users/omarkn/Sites/chu/o

UNIX is elegant!

bw,
Omar KN

Last edited by OmarKN; 07-11-2012 at 10:45 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Move parent folder if contents match a parameter

Hi all, Hoping someone can help. I'm looking to be able to search a particular folder path for folders that contain certain files / formats and then move the parent folder. eg. /foo/bar/folder1/file.exe /foo/bar/folder2/file.exe and then move the folder1/2 tp another folder. So if... (1 Reply)
Discussion started by: springs2
1 Replies

3. Shell Programming and Scripting

To replace a string in file by its parent folder name.

Hi all, I have a directory structure like "folder1/folder2/website_name/folder3/folder4/file.php." I need to write a script which will enter into file.php and replace a particular string of characters with "website_name" folder name. In folder2,there are many such website's folders kept.So... (4 Replies)
Discussion started by: arien15488
4 Replies

4. Shell Programming and Scripting

how to grep parent process PID in shell scripting

hi all, for an example: $ ps -ef | grep apache | awk '{ print $2, $3 }' 24073 11784 28021 1 28022 1 28038 1 28041 28040 28045 28041 28047 28041 28040 1 28049 28041 28051 28041 28053 28041 28030 1 28054 28041 28055 28041 28056 28041 28057 28041 (5 Replies)
Discussion started by: raghur77
5 Replies

5. UNIX for Dummies Questions & Answers

Execute grep command within a folder

Experts, i need your help to made an enhance query using the existing one. i'm using a command "find . -exec grep -l 'search string' {} \;" to search a particular sting within the file within a folder. Basically, my idea is to fine tune my search. What i want is, instead of searching all files... (2 Replies)
Discussion started by: gav_dhiman
2 Replies

6. Shell Programming and Scripting

How to read a subfolder one by one in parent folder?

Hi friends, I am getting some trubles in folder reading. I am having 10 subfolders inside server7 folder. i wanna to read a subfolder name first and check if the foldername gets started with "http". if so , i need to read a file inside that folder. This willl continue for... (1 Reply)
Discussion started by: kamatchirajan
1 Replies

7. Shell Programming and Scripting

multiple child scripts running in backgroud, how to use grep on the parent?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (5 Replies)
Discussion started by: albertashish
5 Replies

8. Shell Programming and Scripting

full path of a file situated either in parent's dir. or parent's parent dir. so on...

hi experts(novice people can stay away as it is no child's game), i am developing a script which works like recycle bin of windows. the problem i am facing is that when ever i am trying to delete a file which is situated in parent directory or parent's parent directory i am unable to... (1 Reply)
Discussion started by: yahoo!
1 Replies

9. UNIX for Dummies Questions & Answers

How do I search parent folder only?

I have a directory /dir1/dir2/dir3/dir4/dir5. How can I search for files only in dir4/ and not in dir5? I tried the maxdepth command, but it doesn't work in this flavor of sun OS. When I search for files in dir4, it's giving me results from dir5 as well. I don't want this. Thanks. (3 Replies)
Discussion started by: bbbngowc
3 Replies

10. UNIX for Dummies Questions & Answers

Grep from different folder

Hi All, Need your assistance/advice. I have 4 folders but using same name log file. /user/access/server1 /user/access/server2 /user/access/server3 /user/access/server4 filename is access.log.20060716.gz I want to grep the transaction id in the log file but I want to do... (2 Replies)
Discussion started by: nazri76
2 Replies
Login or Register to Ask a Question