LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 07-15-2009, 01:46 PM   #1
fpp666
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:

Code:
cd $dir_old
for name in *
	do
		diff "$name" "$dir_new$name" >> logfile
	done
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!

Cheers,
Fernando

EDIT: sorry I forgot, I'm using ksh

Last edited by fpp666; 07-15-2009 at 01:47 PM. Reason: Forgot info
 
Old 07-15-2009, 02:18 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
Hello fpp666

You could skip the NCP* files by
Code:
cd $dir_old
for name in *
	do
		if [[ "${name#NCP}" = "$name" ]]; then
			diff "$name" "$dir_new$name" >> logfile
		fi
	done
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.

Best

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

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

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

Cheers!
Fernando
 
  


Reply

Tags
scripting


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 11: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 07:32 AM
SQL SELECT Group by 2 conditions MicahCarrick Programming 1 01-30-2007 11:02 PM
GtkFileChooserDialog: How to select both, files and directories? froedi Programming 0 06-11-2005 08:07 AM
select files with attributes Quis Linux - General 1 04-03-2003 03:48 AM


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

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