|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Grep with parent folder
Hi, When I do Code:
ls -l | grep -h STRING I need not only to get those files, but also the parent folder of those files, no idea how do that. BTW the names of those parent folders are never longer than 3 digits, if that helps. Any assistance most welcome, /bw, OmarKN
Last edited by zaxxon; 07-11-2012 at 03:23 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Can you show the expected output?
|
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Sure, here are the files without their parent folders: i Code:
3: okn$ ls | grep -h _i _i-lklist.txt _img _img2 compig_i.html compst_i.html It's the parent folders which I 'd also like to be listed, :-) bw, Omar KN
Last edited by zaxxon; 07-11-2012 at 03:46 AM.. Reason: code tags... |
|
#4
|
||||
|
||||
|
Code:
find /absolute/path/ -type f -name "*_i*" | while read filename do echo "Parent Folder : $(dirname $filename)" done |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Well this is not bad, I copied it and outcome was: Code:
i3:chello uppd_G5 okn$ find . -type f -name "*_i*" | while read filename; do echo "Parent Folder : $(dirname $filename)"; done Parent Folder : . Parent Folder : ./k Parent Folder : ./k Parent Folder : ./k Parent Folder : ./n Parent Folder : ./naw Parent Folder : ./o Which gives the Parent Folders of those files, but not the file-names themselves, so I don't know in which Parent Folder XY-file is. Is there not a way with grep? Thank you, bw, OmarKN
Last edited by zaxxon; 07-11-2012 at 04:36 AM.. Reason: code tags |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Code:
find /absolute/path/ -type f -name "*_i*" | while read filename do echo "File Name : $(basename $filename)" echo "Parent Folder : $(dirname $filename)" done absolute path --- give the path from / ( root ) |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Nope, sorry: Code:
i3:/ okn$ find /Volumes/main_HD/Users/omarkn/Sites/chello\ uppd_G5 -type f -name "*_i*" | while read filename; do echo "Parent Folder : $(dirname $filename)"; done usage: dirname path Parent Folder : usage: dirname path Parent Folder : usage: dirname path Parent Folder : ... ... And so on, this is from root... bw, OmarKN
Last edited by zaxxon; 07-11-2012 at 04:36 AM.. Reason: code tags |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To replace a string in file by its parent folder name. | arien15488 | Shell Programming and Scripting | 4 | 12-10-2010 01:21 AM |
| how to grep parent process PID in shell scripting | raghur77 | Shell Programming and Scripting | 5 | 06-25-2009 08:36 AM |
| How to read a subfolder one by one in parent folder? | kamatchirajan | Shell Programming and Scripting | 1 | 01-08-2009 04:56 PM |
| full path of a file situated either in parent's dir. or parent's parent dir. so on... | yahoo! | Shell Programming and Scripting | 1 | 07-24-2008 07:24 AM |
| How do I search parent folder only? | bbbngowc | UNIX for Dummies Questions & Answers | 3 | 04-17-2008 04:42 AM |
|
|