Filename check in UNIX

Hello ,

I have to search for the file names which will either has ABC_DEF or NN in their filename

Please note that both cannot appear in the same file name

currently I am using

ls -lrt /zthetl/SrcFiles/*ABC_DEF*.xls| head -1 | nawk '{print $9}'

How to combine the NN in this code?
Kindly let me know

try

ls -ltr | egrep -i "ABC_DEF|NN"

---------- Post updated at 08:04 AM ---------- Previous update was at 07:49 AM ----------

if you want both files to appear then

ls -ltr | egrep -i "ABC_DEF.*NN"
1 Like

Try:

ls -lrt /zthetl/SrcFiles/*ABC_DEF*.xls /zthetl/SrcFiles/*NN*.xls

--
Also you do not need the -l option and the awk filter:

ls -rt /zthetl/SrcFiles/*ABC_DEF*.xls /zthetl/SrcFiles/*NN*.xls | head -1

or

ls -t /zthetl/SrcFiles/*ABC_DEF*.xls /zthetl/SrcFiles/*NN*.xls | tail -1

:smiley: :b:

bash and zsh also allow

ls -1t /zthetl/SrcFiles/*{ABC_DEF,NN}*.xls

The -1 option (force 1 column output) is useful in an interactive shell.