what's wrong with my regex using find


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting what's wrong with my regex using find
# 1  
Old 08-02-2012
what's wrong with my regex using find

Code:
#ls json-*
json-lexer.c  json-lexer.h  json-parser.c  json-parser.h  json-streamer.c  json-streamer.h

Code:
#find . -regex '^(json-)[a-z]+.[ch]'

return nothing
# 2  
Old 08-02-2012
The regex option with find is funky to say the least. You have to account for the that leading "./" in the path leading to the file in your regex.

This works, but tweak to your tastes:

Code:
find -regextype awk -regex '.*json-[a-z]+\.[ch]'
./json-streamer.c
./json-parser.h
./json-parser.c
./json-lexer.h
./json-lexer.c

Hope this helps.
# 3  
Old 08-02-2012
I'm not sure. Fortunately this is simple enough no regex is needed.

Code:
find . -name 'json-*.[ch]'

-name always requires the glob to match the entire filename.

This will also work on more systems, since few actually support -regex.
# 4  
Old 08-02-2012
Quote:
Originally Posted by in2nix4life
The regex option with find is funky to say the least. You have to account for the that leading "./" in the path leading to the file in your regex.

This works, but tweak to your tastes:

Code:
find -regextype awk -regex '.*json-[a-z]+\.[ch]'
./json-streamer.c
./json-parser.h
./json-parser.c
./json-lexer.h
./json-lexer.c

Hope this helps.


really strange, haha

---------- Post updated at 09:55 AM ---------- Previous update was at 09:55 AM ----------

Quote:
Originally Posted by in2nix4life
The regex option with find is funky to say the least. You have to account for the that leading "./" in the path leading to the file in your regex.

This works, but tweak to your tastes:

Code:
find -regextype awk -regex '.*json-[a-z]+\.[ch]'
./json-streamer.c
./json-parser.h
./json-parser.c
./json-lexer.h
./json-lexer.c


./ will break my thought
Hope this helps.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What is wrong with 'find . -maxdepth 1 -ctime -7 -type f'?

Have you tried running the command below? On the same RHEl 6.8 or 6.6. It will give you different output. find . -maxdepth 1 -ctime -7 -type f rpm -qa|grep find findutils-4.4.2-9.el6.x86_64 # cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.8 (Santiago) # (6 Replies)
Discussion started by: invinzin21
6 Replies

2. UNIX for Dummies Questions & Answers

Perl find & replace - what am I doing wrong?

Hi! I have a directory full of .plist type files from which I need to delete a line. Not every file contains the line, but of course I'd like to do it recursively. The line which I want to delete is: <string>com.apple.PhotoBooth</string> and looks like this in its native habitat: ... (9 Replies)
Discussion started by: sudon't
9 Replies

3. Shell Programming and Scripting

what's wrong with my -exec in find

find ./ -name *Kconfig -exec cat {} \; but it won't work with find ./ -name *Kconfig -exec cat {} |grep CONFIG_MTD |grep depend \; how could I handle this (14 Replies)
Discussion started by: yanglei_fage
14 Replies

4. Shell Programming and Scripting

regex help with 'find'

How to do alternation using regular expressions in the 'find' command? Like say you want to find all files that do not match the names specifically "this" or "that" within a directory using regular expressions? (10 Replies)
Discussion started by: stevensw
10 Replies

5. Shell Programming and Scripting

Find regex

Hi There, Can anybody help me out for searching this regular expression? xxxxx.yyy.zzzz.From-ABCD.To-XYZ.xxxxxx I would like the ID1 and ID2 (knowing which one is Id1 and id2) .From-<ID1>. and .To-<ID2>. Thanks in advance!! Regards, Bhaskar (4 Replies)
Discussion started by: bhaskar_m
4 Replies

6. Shell Programming and Scripting

Wrong output in find command

Hi guys - I am trying a small script to tell me if there is a file that exists less than 1k. It should report ERROR, otherwise the check is good. I wrote this script down, however it never runs in the if/then statement. It always returns the echo ERROR. MYSIZE=$(find /home/student/dir1... (8 Replies)
Discussion started by: DallasT
8 Replies

7. UNIX for Advanced & Expert Users

what is wrong with this find command

i am trying to find the files which are more than 100MB and it was created 10 days ago. find /lola/loaded -size +102400 -mtime -10 -print | xargs ls -ltr -rw-rw-r-- 1 lola_adm gdrmp 82054170 Jun 23 06:17 /lola/loaded/ILMEMBER20090622.txt -rw-rw-r-- 1 lola_adm gdrmp 652080494 Jun 24... (3 Replies)
Discussion started by: sudhiroracle
3 Replies

8. Shell Programming and Scripting

whats wrong with this find statement ?

cmd="find /a/technologies -name '*.jar' | grep \"Tuning/specificloader/lib\"" echo $cmd for index in `$cmd` do SL_JARS="${SL_JARS}:${index}" done gives error ==> find: paths must precede expression Usage: find but for index in... (2 Replies)
Discussion started by: crackthehit007
2 Replies

9. Shell Programming and Scripting

Find with RegEx

I have some files in unix ls -1 TMH.backend.tar.421E-03.Z TMH.backend.tar.421E-04.Z TMH.backend.tar.421E-05.Z TMH.backend.tar.421E-06.Z TMH.backend.tar.421E-07.Z TMH.backend.tar.421E-08.Z TMH.backend.tar.421E-08.Z.bak20081223164844 TMH.backend.tar.421E-09.Z... (1 Reply)
Discussion started by: on9west
1 Replies

10. Shell Programming and Scripting

what i do wrong, find grep rm, help me plz

hello. i need find folders only with name 2006 and delete. find /path/to/dir/-07/ -type d | grep 2006 | -exec rm -rf {} \; and etc doesnt work :\ what i do wrong :? (4 Replies)
Discussion started by: djdes22
4 Replies
Login or Register to Ask a Question