Skip to content
Advertisement

Unable to get the output using regex

This might be a silly one, but I’m unable to get the required output.

I’ve a file named Abc_sfgf_kjwefgk.txt20180929_040845 in a directory.

I’m trying to list the file using the command: ls -l Abc_sfgf_kjwefgk.txt[0-9]{8}_[0-9]{4}

But it’s giving me error: ls: cannot access 'Abc_sfgf_kjwefgk.txt[0-9]{8}_[0-9]{4}': No such file or directory

While, with this command:ls -l Abc_sfgf_kjwefgk.txt[0-9]*?_[0-9]*?

It’s giving me the correct result.

What’s the problem with my initial command?

Advertisement

Answer

Seems like everything is okay with your SECOND command. Here you correctly use globbing.

If you want to parse ls, then you should use smth like this:

ls | grep -E 'Abc_sfgf_kjwefgk.txt[0-9]{8}_[0-9]{4}'
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement