Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-15-2009, 12:46 PM   #1
LQ Newbie
Registered: Jul 2009
Posts: 10

Rep: Reputation: 0
How can I select all files except a group?

Hi again!

I'm very new to shell scripting, and I need a way to do the following:

I have directory (dir_new) with a list of 15 files that I have to compare (using diff) with the same files on another directory (dir_old).

Three of those files are not supposed to be compared, so I need to leave them out of the test. All files have different names, but these 3 files all start with the same initial (NCP).

I need to know how can I leave those three files out of the FOR sentence that I use to diff the rest of the files. This is what I have:

cd $dir_old
for name in *
		diff "$name" "$dir_new$name" >> logfile
I don't know what to use instead of the * on the first line, that will allow me to use all the files except the ones that start with NCP. I tried for name in !NCP* and one or two variables, but I had no luck so far.

I'd really appreciate some help!


EDIT: sorry I forgot, I'm using ksh

Last edited by fpp666; 07-15-2009 at 12:47 PM. Reason: Forgot info
Old 07-15-2009, 01:18 PM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Hello fpp666

You could skip the NCP* files by
cd $dir_old
for name in *
		if [[ "${name#NCP}" = "$name" ]]; then
			diff "$name" "$dir_new$name" >> logfile
You could also do it by altering the file name expansion * but I'm not confident of being able to advise how to do that in ksh. The above will work in any (almost any!) Bourne shell derivative.


Old 07-16-2009, 02:17 AM   #3
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Stretch/Sid, Linux Mint DE
Posts: 4,632

Rep: Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711Reputation: 711
Assuming that ksh also has the $(...) construct:
for name in $(ls -I 'NCP*')
Old 07-16-2009, 07:31 AM   #4
LQ Newbie
Registered: Jul 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Thank you very much, you've been really helpful!!




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sql - select, count, join, group true_atlantis Programming 1 11-19-2008 10:07 PM
in copy files or ls files the command want to invert select some files how to?? hocheetiong Linux - Newbie 3 06-27-2008 06:32 AM
SQL SELECT Group by 2 conditions MicahCarrick Programming 1 01-30-2007 10:02 PM
GtkFileChooserDialog: How to select both, files and directories? froedi Programming 0 06-11-2005 07:07 AM
select files with attributes Quis Linux - General 1 04-03-2003 02:48 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration