The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
listing files excluding files from control file ukatru UNIX for Advanced & Expert Users 15 08-15-2008 09:24 PM
Listing Files krishna_sicsr High Level Programming 3 04-05-2007 02:32 PM
Listing of files Vitalka Linux 1 03-02-2005 09:32 AM
help - listing files richarmj Filesystems, Disks and Memory 2 10-02-2003 10:14 AM
Recursive directory listing without listing files psingh UNIX for Dummies Questions & Answers 4 05-10-2002 11:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-23-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Listing all the files names not starting as

hello all,
iam new to shell scripting.I have searched the forum and could'nd find a close enough answer and hence this post:

I want to list all the file names whose names don't start as abc.

For example if my folder constains files with names: abc123.txt,erdf23.rdf,ed45r.fmb

i want a command which will list only files erdf23.rdf,ed45r.fmb and omit the file abc123.txt.

the ls command does'nt seem to have a -not option
  #2 (permalink)  
Old 11-23-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,311
Code:
ls -1 !(abc*)
If you have files in underlying directories and you want to omit them:

Code:
ls -ld !(abc*)|awk '!/^d/{print $NF}'
  #3 (permalink)  
Old 11-23-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Perfect Franklin...Thank You very much
  #4 (permalink)  
Old 11-23-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Quote:
Originally Posted by Franklin52 View Post
Code:
ls -1 !(abc*)
If you have files in underlying directories and you want to omit them:

Code:
ls -ld !(abc*)|awk '!/^d/{print $NF}'
Sorry Frank ...If i have to elimiate more than one name in the file how do i do it?

i mean don't select files whose name starting with abc or efg

ls -ld !(abc*,efg*)|awk '!/^d/{print $NF}' don't seem to work
  #5 (permalink)  
Old 11-23-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,311
Try this:
Code:
ls -l |awk '/^-/ && $NF !~ /^abc/ && $NF !~ /^efg/ {print $NF}'
  #6 (permalink)  
Old 11-24-2008
valluvan valluvan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 27
Quote:
Originally Posted by Franklin52 View Post
Try this:
Code:
ls -l |awk '/^-/ && $NF !~ /^abc/ && $NF !~ /^efg/ {print $NF}'
Thanks Frank when I assign this code to a variable and try to print the variable contents it just prints nothing.

I do this:

FILELIST=`ls -l |awk '/^-/ && $NF !~ /^abc/ && $NF !~ /^efg/ && $NF ~ /.out/ {print $NF}'`
echo $FILELIST


Neither does this work:
FILELIST=`echo ls -l |awk '/^-/ && $NF !~ /^abc/ && $NF !~ /^efg/ && $NF ~ /.out/ {print $NF}'`
echo $FILELIST

Please help..Ideally it shold be printing the file name whose extension is .out and not begining with abc or efg
  #7 (permalink)  
Old 11-24-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,311
It should work, post the output of ls -l within code brackets.

Regards
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0