Filename check in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filename check in UNIX
# 1  
Old 04-30-2014
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

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

How to combine the NN in this code?
Kindly let me know
# 2  
Old 04-30-2014
try

Code:
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

Code:
ls -ltr | egrep -i "ABC_DEF.*NN"

This User Gave Thanks to Makarand Dodmis For This Post:
# 3  
Old 04-30-2014
Try:
Code:
ls -lrt /zthetl/SrcFiles/*ABC_DEF*.xls /zthetl/SrcFiles/*NN*.xls





--
Also you do not need the -l option and the awk filter:
Code:
ls -rt /zthetl/SrcFiles/*ABC_DEF*.xls /zthetl/SrcFiles/*NN*.xls | head -1

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


Last edited by Scrutinizer; 04-30-2014 at 11:13 AM..
# 4  
Old 04-30-2014
Smilie Smilie
# 5  
Old 04-30-2014
bash and zsh also allow
Code:
ls -1t /zthetl/SrcFiles/*{ABC_DEF,NN}*.xls

The -1 option (force 1 column output) is useful in an interactive shell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX script to display the filename

Hi All How to answer the below interview question.. With a path and filename of "/mydir1/mydir2/mydir3/myfilenane.dat" write a UNIX script to display the filename (2 Replies)
Discussion started by: shumail
2 Replies

2. Windows & DOS: Issues & Discussions

Check dir for overly path+filename and list in txt

Well since Windows always laments over some of my files having a too long "path+filename" and it gets in the way of copying complete directory structures I would love to have a DOS Script that helps me with finding those. I already tried DCSoft Long Filename Finder but that is neither DOS based... (3 Replies)
Discussion started by: pasc
3 Replies

3. Shell Programming and Scripting

How to check if a filename in a directory starts with a certain string

Hello, Trying to iterate over set of file in current directory and check if the file name in that folder matches certain string. This is what I have so far. Here I am checking if the file name starts with nexus, if so echo file name to log file. Getting weird syntax errors. Any help is... (7 Replies)
Discussion started by: scorpioraghu
7 Replies

4. Shell Programming and Scripting

Please help I want script to check filename, size and date in specify path.

Please help, I want script to check filename, size and date in specify path. I want output as: DATE: YYYYMMDD HH:MM ------------------------------------------------ fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd HH:MM fileA,filesize,yyyy mm dd... (1 Reply)
Discussion started by: akeji
1 Replies

5. Shell Programming and Scripting

How can I get only FileName associated with a INODE on Unix much faster?

How can I get only FileName associated with a INODE on Unix in seconds instead of minutes, as it is the case for me as shown below. # Say I have FileDescriptor: 43, INODE: 2590784, File: abc.rdb. I want to get only filename associated with inode:2590784 and FD:43. $> time find / -inum... (7 Replies)
Discussion started by: kchinnam
7 Replies

6. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

7. Shell Programming and Scripting

to check whether a directory or filename path is valid or not

the script on excution should take a directory path from useran a numric input and it should check indicate whether its write or not? if the cmmd sh<script-name>,dir/path.<500>" is greater than 500 in size should be copied to dir ,temp in pwd and display the mesage'files of 2000 bytes hav been... (4 Replies)
Discussion started by: arukr
4 Replies

8. UNIX for Dummies Questions & Answers

unix file system V filename limit

Why unix system V has a filename size limit of 14 characters.How other versions of Unix got around this problem.Can anybody help? (7 Replies)
Discussion started by: admirer
7 Replies

9. Shell Programming and Scripting

filename extension check - regular expression

How to compare the file name for "zip" or "ZIP" extension. I can put one more || condition to check the upper case in the below: if ]; then Is there any better way to compare using regular expressions. Thx in advance. (4 Replies)
Discussion started by: devs
4 Replies

10. UNIX for Dummies Questions & Answers

UNIX Filename length restrictions?

Can anyone help me out with information on the filename length restrictions in UNIX? Thanks! (2 Replies)
Discussion started by: xmeh
2 Replies
Login or Register to Ask a Question