0

enter image description here

I matched the data in directories r09 r10 by the following command:

find r[0-9]* -name '\*-ch24-\*' | sed -e 's|r[0-9]*/n_ch24/||' > sim_sets1.txt 

but got confused, why it's not find r[0-9]\* -name '.\*-ch24-.\*?

1 Answer 1

2

*-ch24-* is a glob. -name matches globs. For a glob, * matches zero or more of any character.

.*-ch24-.* is a regular expression. If you want to match on regular expressions, use -regex instead of -name. In a regex, . matches any character and * is a quantifier which means zero or more of the preceding character.

Sign up to request clarification or add additional context in comments.

6 Comments

Indeed; also worth pointing out that escaping * as \* inside a single- or double-quoted string will cause it to be treated as a literal by find, so it's implausible that find r[0-9]\* -name '\*-ch24-\*' worked as intended.
Oh * is just for the editing markup here in stack-overflow, a typo. Thanks for pointing this out.
@John1024 another quick question will be non-relevant to shell, but how to use command-line perl to achieve the same functionality?
@user1961679 Just to confirm, the backslashes that now appear in the question are editing markup, not part of an actual command? Separately, to use command-line perl, replace the sed command with the very similar perl command: perl -pe 's|r[0-9]*/n_ch24/||'
@John1024 Bow// How about the 'find' part, is there any perl equivalent to that? Also perl -p: from man, '-p assume loop like -n but print line also, like sed', what does this mean, means 'print'? Thanks.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.