![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ..??) |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|
#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.
|
|
#4
|
|||
|
|||
|
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> |
|
#5
|
|||
|
|||
|
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 .... I hope this helps. bakunin |
|
#6
|
|||
|
|||
|
Code:
ls -1 code.[0-9]* | egrep -E ".[0-9]+$" | xargs rm |
|
#7
|
|||
|
|||
|
Thanks bakunin this is working ... !
|
|||
| Google The UNIX and Linux Forums |