remove files other than selected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove files other than selected
# 15  
Old 11-28-2007
Quote:
Originally Posted by radoulov
Strange,
could you post the output from your commands?

in ksh:

Code:
ls -l
ls -l !(*test*)




-----------------------
$ ls
g_test1 test_11.dat test_3.dat test_6.dat test_9.csv test_dd.dat test_mrg1.dat
test_1.dat test_11.txt test_4.dat test_7.dat test_d.dat test_dt.txt test_script.ksh
test_10.csv test_2.dat test_5.dat test_8.csv test_d2.dat test_mrg.dat
$ ls -l !(*test*)
ls: 0653-341 The file !(*test*) does not exist.
-------------------------------------------------
# 16  
Old 11-28-2007
Quote:
Originally Posted by freakygs
-----------------------
$ ls
g_test1 test_11.dat test_3.dat test_6.dat test_9.csv test_dd.dat test_mrg1.dat
test_1.dat test_11.txt test_4.dat test_7.dat test_d.dat test_dt.txt test_script.ksh
test_10.csv test_2.dat test_5.dat test_8.csv test_d2.dat test_mrg.dat
$ ls -l !(*test*)
ls: 0653-341 The file !(*test*) does not exist.
-------------------------------------------------
EDIT:

The output is correct!
You don't have files that don't have the "test" pattern in the name!

Could you post the ksh version also, thanks!

Code:
print $KSH_VERSION

or

Code:
print ${.sh.version}

# 17  
Old 11-28-2007
So:

Code:
rm -f !(*test*)

Use -f to suppress error messages (I don't know if ksh has the nullglob option Smilie).
# 18  
Old 11-28-2007
Quote:
Originally Posted by radoulov
EDIT:

The output is correct!
You don't have files that don't have the "test" pattern in the name!

Could you post the ksh version also, thanks!

Code:
print $KSH_VERSION

or

Code:
print ${.sh.version}



both these cmds don't work on my machine
# 19  
Old 11-28-2007
Quote:
Originally Posted by freakygs
both these cmds don't work on my machine
It's possible (you have ksh88 I suppose),
but the globbing I suggested should work.
You can always redirect/suppress the error messages
when no match is found.
# 20  
Old 11-28-2007
Quote:
Originally Posted by grial
find /path/to/files -type f ! -name '*test*' -exec rm {} \;
This should work. Have you tryed it?
# 21  
Old 11-28-2007
Quote:
Originally Posted by radoulov
It's possible (you have ksh88 I suppose),
but the globbing I suggested should work.
You can always redirect/suppress the error messages
when no match is found.
hey... thanks a lot.... .that script worked..... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

unzip selected files

Hi, In file zip folder i have many files but i want to extract onlu .LOG file from the zip. How can i achive this Rajesh (3 Replies)
Discussion started by: guddu_12
3 Replies

2. Shell Programming and Scripting

Shell to remove a newline char from selected rows in a file.

Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 ... (3 Replies)
Discussion started by: mailme0205
3 Replies

3. UNIX for Dummies Questions & Answers

Remove a newline char from selected rows.

Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 ... (2 Replies)
Discussion started by: mailme0205
2 Replies

4. Shell Programming and Scripting

Script to find and email selected files

I am trying to come up with a script that will search for selected files and then email them to me. For example, say I have a directory that has the following files: AA_doug.txt AA_andy.txt BB_john.txt APPLE_mike.txt GLOBE_ed.txt GLOBE_tony.txt TOTAL_carl.txt what is the best way to... (2 Replies)
Discussion started by: coach5779
2 Replies

5. Shell Programming and Scripting

compare two files, selected columns only

hi! i have two files that looks like this file 1: ABS 123 456 BCDG 124 542 FGD 459 762 file 2: ABS 132 456 FGD 459 762 output would be: from file1: ABS 132 456 BCDG 124 542 from file 2: ABS 132 456 (4 Replies)
Discussion started by: kingpeejay
4 Replies

6. Shell Programming and Scripting

gzip selected files that do not contain the string...

Solaris 10 Hi All, Can anyone give me a simple way of gzipping select files that end with *.dmp and where the filename does not contain the string "nocompress" I had a go but failed miserably :-( Thanks in advance Satnam (3 Replies)
Discussion started by: satnamx
3 Replies

7. Shell Programming and Scripting

trying to print selected fields of selected lines by AWK

I am trying to print 1st, 2nd, 13th and 14th fields of a file of line numbers from 29 to 10029. I dont know how to put this in one code. Currently I am removing the selected lines by awk 'NR==29,NR==10029' File1 > File2 and then doing awk '{print $1, $2, $13, $14}' File2 > File3 Can... (3 Replies)
Discussion started by: ananyob
3 Replies

8. Shell Programming and Scripting

concatenating selected lines of multiple files

Hi, I would like a shell script that reads all files in a directory and concatenate them. It is not a simple concatenation. The first few lines of the files should not be included. The lines to be included are the lines from where 'START HERE' appears up to the end of the file. For example, I... (4 Replies)
Discussion started by: laiko
4 Replies

9. Linux

Unzip selected files in .tar.gz file

Hi All, By accident, i deleted some files. Fortunately I have a backup backup.tar.gz files (750GB). It's too big for me to untar to get the file Is it possible that i could get the selected files in backup.tar.gz if i know exactly where the files are located. Thanks. Ken (1 Reply)
Discussion started by: trongkhuongsg
1 Replies

10. UNIX for Dummies Questions & Answers

ftp selected jpeg files from unix filesystem

Hi All We have hp-ux 11iv1 system running with oracle8i database. We have around 350,000 users, each user uploaded their own signatures and are stored in unix filesystems department wise. A database is maintained to keep their particulars with a path to link their signature files. Now... (3 Replies)
Discussion started by: mhbd
3 Replies
Login or Register to Ask a Question