I am new to regex, I want to list file matching with given regex. I have some samples files as shown in below picture
I want regex which should return below mentioned files:
test1.csv test2.csv test3.csv test9.csv.tt
I want to use the find command for this and i also tried with below mentioned find command but could not achive my expected results
find . -maxdepth 1 -type f -name "**test[0-9]*[^-a-zA-Z_]***.csv*" -exec ls -l {} +
I want to use same commnad to achieve my expected output only i want correct regex.
Anyone have any idea please do help!
Using find
, you can try:
find . -type f -regex ./test[0-9]\\*.csv.\\* -exec ls -l {} +
Or, using sed
, you can try
$ ls -l | sed '/^d/d;/ test[0-9]*\\.csv.*/!d'
(not sure if digits are mandatory -- if they're, then replace *
by +
)
There are 2 commands in this sed
.
/^d/d
deletes any row that starts with a d
(exclude directories) / test[0-9]*\\.csv.*/!d
removes any row that doesn't match the regex you want to filter by.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.