Reputation: 29
I have 2 files.
`File 1 = ABC2019120601C`
`File 2 = ABC2019120611C`
If I type ls -l ABC*C it will output all 2 files. Is there a way to find files by exact position of the character?
For example
1st position = A
2nd position = B
3rd position = C
and 14th position = C
Then it will output only the file ABC2019120601C
Please help if this is possible
Thanks
Upvotes: 0
Views: 322
Reputation: 14442
On surface, the ASK is to find files regardless of the embedded date-time (probably YYYYMMDDHH). This translates into 'ABC[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]C' pattern. Either printf
or find
will work.
# Single Folder
printf '%s\n' ABC[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]C
# Multiple folders, deep search
find /folder1 /folder2 -name 'ABC[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]C'
Upvotes: 0
Reputation: 6048
Bash globbing has more than just *
, e.g. ?
, which means "any single character":
$ ls -1 ABC*C
ABC2019120601C
ABC2019120611C
$ ls -1 ABC????????0??
ABC2019120601C
$ ls -1 ABC????????1??
ABC2019120611C
Upvotes: 1