INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Omitting few folder from a folder

Omitting few folder from a folder

(OP)
Hi All,

I have a list of directories like below

Folder Path is
$GLOG_HOME/web/htdocs/js
Folders are

rateservice
ratepreference
ratefactor
dev123
I want to omit all folders and select only dev123 folder,

I have tried

#!/bin/bash

. $HOME/.profile
cd $GLOG_HOME/web/htdocs/js
touch custom_js_files.txt

ls -p grep -v 'rateservice'| grep-v 'ratepreference'| grep-v 'ratefactor'> custom_js_files.txt

I have tried grep -R for directories also. Please suggest on it.

Thanks,
Dev Rishi


RE: Omitting few folder from a folder

grep -v inverts the results so you get lines that do not match the pattern.


If you already know the folder name the simplest way of course is just to specify only that folder in the path.

grep [pattern] $GLOG_HOME/web/htdocs/js/dev123/* ... ...

Is there some compelling reason that cannot be done?

Quote:

I have tried grep -R for directories also.
-R is to parse all subdirectories including symbolic links.

--exclude-dir foldername(s) will 'exclude' named directories

$ man grep on the CLI will tell you this.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: Omitting few folder from a folder

(OP)
Thanks Chris,

I know only folders which i want to omit. The folder I wan to capture is dynamic and it can change.

So I need a script to omit all folders I know and list down which are not known or can change.

Thanks,
Dev

RE: Omitting few folder from a folder

In that case, --exclude-dir is the option to use

and from your example structure;

CODE --> bash

grep -r [pattern] [top-level-folder/filespec] --exclude-dir 'ra*' 
for example will exclude physical directories where the name begin with ra and if you have more to exclude just concatenate additional --exclude-dir options

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

RE: Omitting few folder from a folder

The Korn shell has a pattern for matching 'NOT' something...

CODE --> /bin/ksh

ls -lad !(rate*) 

That will match everything that does NOT start with "rate".

RE: Omitting few folder from a folder

(OP)
Hi Chris,

What should I give in pattern. I do not have any specific pattern.

Thanks,
Dev

RE: Omitting few folder from a folder

Quote:

What should I give in pattern

Whatever the text is you are grepping the files for.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close