The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pattern Matching problem in UNIX maxmave Shell Programming and Scripting 2 06-02-2008 10:19 PM
Pattern Matching in UNIX maxmave Shell Programming and Scripting 2 05-14-2008 12:21 PM
pattern matching in an if-then lumix Shell Programming and Scripting 4 12-14-2007 01:25 PM
pattern matching larryase UNIX for Dummies Questions & Answers 3 11-22-2004 03:54 PM
Pattern Matching danhodges99 UNIX for Dummies Questions & Answers 2 02-27-2003 12:03 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 09-24-2008
Registered User
 

Join Date: Sep 2008
Posts: 3
pattern matching in unix

Task is to identify files like code.1 , code.23 and so on ... (the files which are ending with a number) but it should not match files like code.123abc. So the search will normally search for files with "code." and at the end we should extract for the correct match. Now I have to remove these files interactively i.e 'rm -i '. Now please let me know any oneliner in unix or perl to perform this task.
I tried : find . -name "code.[0-9]* -exec rm -i {} \; (but this will not work ..??)
Reply With Quote
Forum Sponsor
  #2  
Old 09-24-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,031
As find is not using Regular Expressions, you might want to use something like:

Code:
find . -print| grep code.[0-9]*$| xargs -p rm -i
Reply With Quote
  #3  
Old 09-24-2008
Registered User
 

Join Date: Sep 2008
Posts: 3
I see that grep is not a correct match .. even if that grep works ... I am unable to parse files and remove them interactively.
Reply With Quote
  #4  
Old 09-24-2008
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,031
Show your error message please. Also I don't understand what you mean by "grep is not a correct match". xargs -p and rm -i should ensure it will be interactively:

Code:
root@isau02:/data/tmp/testfeld> ls -la
insgesamt 8
drwxr-xr-x 2 isau users 4096 2008-09-24 11:11 .
drwxr-xr-x 7 isau users 4096 2008-07-09 14:36 ..
-rw-r--r-- 1 root root     0 2008-09-24 11:11 code.123
-rw-r--r-- 1 root root     0 2008-09-24 11:11 code.123abc
-rw-r--r-- 1 root root     0 2008-09-24 11:11 code.123.abc
root@isau02:/data/tmp/testfeld> find . -type f -print| grep code.[0-9]*$| xargs -p rm -i
rm -i ./code.123 ?...n
root@isau02:/data/tmp/testfeld>
Reply With Quote
  #5  
Old 09-24-2008
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,262
You could use several "-name" clauses for find to exclude the files you do not want:

Code:
find /some/dir -name "code.[0-9]*" ! -name "*[a-z]" -exec ....
The exclamation mark is a logical NOT. "! -name x" find everything except a file named "x".

I hope this helps.

bakunin
Reply With Quote
  #6  
Old 09-24-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Code:
ls -1 code.[0-9]* | egrep -E ".[0-9]+$" | xargs  rm
Reply With Quote
  #7  
Old 09-24-2008
Registered User
 

Join Date: Sep 2008
Posts: 3
Thanks bakunin this is working ... !
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:25 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0