List file name problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting List file name problem
# 1  
Old 04-28-2014
List file name problem

For etc, I have 3 files in /testing folder
apple.sh
orange.sh
pear.sh

if I want to find out the apple.sh
It easy, I can type
Code:
ls -ltr *apple*

Expected result:
apple.sh

but, the problem is coming up from my mind. How can I find the others .sh files without the file name "apple.sh"?

Expected result:
orange.sh
pear.sh
# 2  
Old 04-28-2014
It would become cumbersome with standard globbing. You could try extended globbing instead:
Code:
ls !(*apple*)

This functionality is on by default in ksh93 and in bash you need to switch it on first:
Code:
shopt -s extglob

Alternatives would be inverse matching using grep:
Code:
ls | grep -v orange

or use something like:
Code:
for file in *
do
  case 
    $file in (*orange*) continue
  esac
  printf "%s\n" "$file"
done


Last edited by Scrutinizer; 04-28-2014 at 12:54 AM..
# 3  
Old 04-28-2014
If i understand correctly, you want to list all files ending with .sh extension.
You can do the below step:
Code:
ls *.sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in making a list with awk

Hi bodies,I am doing a list from a .txt file with awk commands but something is wrong. The .txt file looks like: 32782 28 18 32783 02 18 32784 01 18 32785 29 18 32786 25 23 32787 25 18 32788 00 18 32789 25 26 32790 02 23 32791 29 26 ... (2 Replies)
Discussion started by: Behrouzx77
2 Replies

2. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

3. Shell Programming and Scripting

Argument list too long problem

I have a huge set of files (with extension .common) in my directory around 2 million. When I run this script on my Linux with BASH, I get /bin/awk: Argument list too long awk -F'\t' ' NR == FNR { a=NR } NR != FNR { sub(".common", "", FILENAME) print a, FILENAME, $1 } '... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

4. Shell Programming and Scripting

BASH: File name part to list reference problem.

I've made a habit of including a four-letter "tail" on image file names I download from the Web, so I can both match them with IPTC Transmission References of my own making and rename them later using either a GUI renamer or a script I've written myself. Now I want to automate the process of... (2 Replies)
Discussion started by: SilversleevesX
2 Replies

5. Shell Programming and Scripting

Convert perl qw list to text file list?

Does anyone have a good example? I am having trouble looping.. Thanks (1 Reply)
Discussion started by: mrlayance
1 Replies

6. Shell Programming and Scripting

Numerically sort problem for a long list of file name

I got a long list of file name. My input: data_1.txt data_2.txt data_3.txt data_10.txt data_21.txt data_12.txt data_4.txt My desired output: data_1.txt data_2.txt data_3.txt data_4.txt data_10.txt data_12.txt data_21.txt Does anybody got idea how to archive it? (11 Replies)
Discussion started by: patrick87
11 Replies

7. UNIX for Dummies Questions & Answers

List certain file in a folder and make list

Hi, im having problem that frustate me today. there are list of file in a folder that i want to grab the folder /subject/items/ in this folder there are this file CREATE_SUBxxxx.xml UPDATE_SUBxxxx.xml DELETE_SUBxxxx.xml loginresponsexxxxx.xml core how can i grab all the file... (1 Reply)
Discussion started by: andrisetia
1 Replies

8. Shell Programming and Scripting

problem feeding netcat a list of hosts

Hi, I'm having difficulty in making a bash script to get netcat to scan a list of hosts and their ports from another file and could use some help. Here's an example host list, "nc.host": 192.168.2.110 22 And here's the first script I tried to feed "nc.host" into netcat: "nc1.sh" ... (3 Replies)
Discussion started by: seanovision
3 Replies

9. AIX

weird file list problem

When I do a file list in my spooler directory, I get the following information #ls -l |pg -rw-rw-rw- 1 user1 ugroups 831690 Apr 03 12:52 K6A80403125051.prn :res 2330479869879093344 ext 2330477052380546512 align -rw-rw-rw- 1 user1 ugroups 5900 Apr 03 14:19 K6A80403141858.idx :res... (8 Replies)
Discussion started by: jmmora
8 Replies

10. Shell Programming and Scripting

List script problem

Hi all, First of all compliments on the forum here. Looks great and has lots of information, some of which I have been able to use. I am a relativ noob when it comes to Unix but already I have been fooling around with scripts for the company I work for here in switzerland! Thanks to this... (2 Replies)
Discussion started by: swissman24
2 Replies
Login or Register to Ask a Question