shell script: forbid extension


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers shell script: forbid extension
# 1  
Old 03-25-2004
shell script: forbid extension

Rather new to unix, so please don't beat me!

I'm trying to get a list of files into a variable that I can use throughout the rest of the script. The challenge is that I need to exclude a certain extension from the list, and I'm having trouble with it. For example:

item_a
item_a.exe
item_a.txt
item_b
item_b.exe
item_b.txt
item_t
item_x

list=`ls -l item*[^txt\$] | awk '{print $9}'`

At first, I thought this would work, but apparently both t and x are forbidden, thus eliminating potential files from my list. I need to exclude a block of characters, not a range of individual characters. I have spent hours searching for the answer (and learned a lot of other stuff along the way), but I can't figure this one out. Any help would be appreciated.
# 2  
Old 03-25-2004
If ksh use...

list=!(*.txt)

...it might work in other shells too.
# 3  
Old 03-25-2004
@Ygor
I don't know much at all about ksh, although from what I gather it's not too different from sh (about the extent of my knowledge on the subject). This script is using sh, and that didn't work, however, I will keep it in mind.

BTW - I've learned more from what *didn't* work than from what did, so that will go on my list of "glad to know it" stuff.

@Driver
I ran into that problem with the curly braces after I posted the message. However, I hadn't tried all the different flags for grep, and that worked perfectly for what I need. Thanks!
# 4  
Old 03-25-2004
Don't use ls -l for this. Ir produces extra fields for you to later strip away.

ls -d item*

will give you a list of files that start with "item".

The -d will handle the case where you have a directory named "itemdir" or something. We will list the directory itself, but not the contents.

Then to get rid of the *.txt files:

ls -d item* | grep -v txt\$
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

2. Shell Programming and Scripting

Finding file extension on C Shell script

I very new to C Shell. I am trying to do is read from Command line. Find the if the file is zip, .txt, symbloic link,pipe, unknow (if file is not zip, txt, sy....) here is what I what got so far. I am very stuck atm Please help me out : If the file is symblooc link what file is link to ... (12 Replies)
Discussion started by: madbull41
12 Replies

3. Shell Programming and Scripting

shell script to change the extension of a file

I have a directory that contains several files, out of which some files are have an extra extension for example file1.new.new.new file2.new.new.new file3.new.new.new file4.new.new.new i want to write a shell script that rename all such file with only single extension like file1.new... (7 Replies)
Discussion started by: mukulverma2408
7 Replies

4. HP-UX

@ character forbid to write in vi.

Hi ALL, I'm encountering this problem on HP Shell (tcsh) environment. Once I enter in vi to edit a file and add my sql script, like this: sqlplus user/pass @promo.sql(tu run my script) the @ character is not possible to write. I push on the key but is not written inside. Also in sqlplus... (3 Replies)
Discussion started by: cicalons
3 Replies

5. Programming

How forbid use fork() in exec() program.

Hello World! I am writing code in C++ which have to launch another application X using exec(). I would like to set some limits on it using setrlimit etc... My problem is that i don't know how to forbid using fork() and strlimit by application X. How can i do it? (3 Replies)
Discussion started by: kzi
3 Replies

6. UNIX for Dummies Questions & Answers

Shell script to rename or change file extension case.

I searched the forum, but there was different type of rename. Hello. I have files in folder. Like: xxxxxxxx1.html or xxxxxxxx2.txt or xxxxxxxx3.tar.gz and how to rename or change file extension case to xxxxxxxx1.htm or xxxxxxx2.TXT or (5 Replies)
Discussion started by: Sheldon
5 Replies

7. UNIX for Dummies Questions & Answers

forbid file recovery

Hi there, When I want to make a file unrecoverable, I use the following command: foo:~$ shred -fuz filename The problem is that I deleted many files using: foo:~$ rm -f filename How can I make those files unrecoverable? Is there a command that shreds the disk free space? So that no file can... (2 Replies)
Discussion started by: chebarbudo
2 Replies

8. Shell Programming and Scripting

shell script string extension

hey, im looking for a way of extending a string in shell script. for example i have two strings "." and "abcd", i need to extend the first string so that it is the same length as the second. so "." and "abcd" becomes "...." and "abcd", could someone shed light on how to do this ? thanks (4 Replies)
Discussion started by: vbm
4 Replies

9. Shell Programming and Scripting

forbid the error message

In my system , there is a script seems have a minor problem but I can't find it out , now everytime run the script , it will generate some error message to the system log , is it possible to forbid it generate the error to the system log or put all these message to /dev/null ? thx (3 Replies)
Discussion started by: ust
3 Replies

10. UNIX for Advanced & Expert Users

How can I forbid a user to go up his home directory

Hi everybody, How can I forbid a user to go up his home directory ? Thanks MarcoW (2 Replies)
Discussion started by: MarcoW
2 Replies
Login or Register to Ask a Question