Instead of * which matches zero or more of any character, you could use ? to indicate a single character, so:-
ls *Hello*.txt
ls ??????Hello???.txt
The first will match any files that has Hello anywhere in the name and finishes with .txt where the second option will only match files that have Hello from character 7, then any three characters and ending .txt
If your current directory has the following files:-
The unquoted glob-expression is evaluated by the shell, so you can as well do
echo ????_????_????OP_?????
ls -1 (or ls if not seeing an interactive terminal) puts output line by line, that is sometimes convenient. Like the following that pipes the output to grep
ls -1 | grep '^...._...._....OP_.....$'
grep uses Regular Expression: . is a single character, ^ is line start, $ is line end.
I have got the answer of how to pick up FORM_PTIR_9820_ANFDOP_20150716_00413561.DAT . But now the problem is DAT can be TXT and there can be lot of files . Like,
So,
I cannot use ????_????_????_????OP_*.??? to transfer all files with OP in middle and ending with .DAT or .TXT to other folder.
????_????_????_????OP_*.???* will pick up .ERROR and .SKIP files as well, so how do I skip the .ERROR and .SKIP files and transfer rest to other folder ?
-------------------------------
Now with ????_????_????_????OP*.??? I will get one file (the last one in above list). How to get a negation of that ? I mean how to list all other files except for these ones which have been derived using the mentioned wildcard ? Please help I tried -I, did not work.
Thanks buddy ! Honestly I know this is getting messy. I would let you know as soon as I have the complete info. Till now, I have asked what I knew of.
---------- Post updated at 04:59 AM ---------- Previous update was at 04:42 AM ----------
Ok guys, this is my exact requirement.
My current working directory.
-rwxrwxr-x 1 dev115 devt 299884 Aug 13 15:09 FORM_PTIR_9820_ANFDOP_20150716_00413562.DAT_bkp
-rwxrwxr-x 1 dev115 devt 299884 Aug 13 15:16 FORM_PTIR_9820_ANFDOP_20150716_00413563.DAT_bkp
-rwxrwxr-x 1 dev115 devt 299884 Aug 13 16:36 FORM_PTIR_9820_ANFDEX_20150716_00413562.DAT
-rwxrwxr-x 1 dev115 devt 299884 Aug 13 16:36 FORM_PTIR_9820_ANFDEX_20150716_00413563.DAT
drwxr-xr-x 2 dev115 devt 4096 Aug 14 09:15 NOTProcessed
-rw-rw-r-- 1 dev115 devt 75 Aug 14 09:15 notify.lst
drwxr-xr-x 2 dev115 devt 4096 Aug 14 09:15 Skipped
drwxr-xr-x 2 dev115 devt 4096 Aug 14 09:15 Processed
drwxr-xr-x 2 dev115 devt 4096 Aug 14 09:15 Error
-rwxrwxr-x 1 dev115 devt 299884 Aug 14 10:15 FORM_PTIR_9820_ANFDOP_20150716_00413561.DAT
=====================================
now I have to move the files which are excluded from the wildcard ????_????_????OP*.??? to a folder called NOTProcessed.
list will give me a set of files which I will have to write in a txt file and then move them one by one.
How can we achieve move with this ?
Say,
ls -ltr | grep -v ????_????_????_????OP*.??? | grep -v ^d
gives me set of all files excluding directory (in any). Now I want to move these files(result set from ls command) to folder NOTProcessed. How can we achieve this ? I want to avoid file names to be written in a txt file and then loop over these names and put one by one. Can we move this in a single command ? Kindly help ! I need it badly...