How to give file name syntax?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to give file name syntax?
# 1  
Old 02-13-2013
How to give file name syntax?

Hello all,
I have one problem. I am designing a script. Which will look for a certain pattern for file name. If pattern matches, then it will pick the file. but I am unable to give proper pattern.

e.g.
Code:
^\$D[0-9]+\.D[0-9]+XF\.[A-Z]+[0-9]+\.log
^SWH_PI_1[0-9]*+\.FIN$

So whenever, any file which will match the above pattern will be get picked.
like
Code:
SWH_PI_123434ABC.FIN

This one I have copied from one reference script. Can someone please let me know how to design the patterns? Or what is the basic thumb rules while creating such patterns. Means when to take which pattern.
I am really confused in
Code:
+\.

or
Code:
[0-9]+\.

or
Code:
 [A-Za-z]

. Please help me to understand such syntaxes or patterns..

Thanks.
# 2  
Old 02-13-2013
Quote:
Originally Posted by akore83
Code:
^SWH_PI_1[0-9]*+\.FIN$

You cannot have two quantifiers * and + one after the other. It either has to be * (0 or more occurrences of the previous character) or + (1 or more occurrences of previous character.
This User Gave Thanks to balajesuri For This Post:
# 3  
Old 02-13-2013
Thank you for the advice.. can you please let me know is it a correct pattern for the file? Ashish_en_Feb07_1.log

Code:
Ashish_en_[A-Za-z]+[0-9]+_1\.log

# 4  
Old 02-13-2013
Yes, and you could even be more specific w.r.t. pattern for date:
Code:
Ashish_en_[A-Za-z]+[0-9]{2}_1\.log

This User Gave Thanks to balajesuri For This Post:
# 5  
Old 02-13-2013
I am sorry to say that it's almost impossible to "teach" you regular expressions and patterns therein. This is very much a matter of experience.
Set up a set of a few close but different filenames, take a book or man pages, and work through them applying patterns after patterns to your file set.
BTW, there's a difference between "pattern" and "globbing" as used in shells for picking files...
This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script give answers by file

Hi, I am new in perl. I am running a perl installation script, its asking for paths and so many inputs. Can we provide that info by any file. so i can avoid the interactive installation. (2 Replies)
Discussion started by: Priy
2 Replies

2. Shell Programming and Scripting

Need to check the value greater than or less than and give out put to a file

HI, I have one file which is as below cat /var/tmp/test1 | awk '{ print $3}'|grep -v affected Data ---------- 200.4 . The above 200 value is changable by the database script. Now I need a script that checks the value 200.4 and the script shoud give out put if value is more than 225 (2 Replies)
Discussion started by: phani4u
2 Replies

3. Shell Programming and Scripting

Take name of input file to give the name of output file

Hello everyone, I think this would be easy for you experts. Refering the suggestion that Scrutinizer gave me in this thread https://www.unix.com/302612499-post13.html I have the script in this form awk '{$1=$1}1' "$1" | awk ' ...' Where "$1" takes the value of "inputfile" then I can... (1 Reply)
Discussion started by: Ophiuchus
1 Replies

4. Shell Programming and Scripting

Search for file, give error if more than one file is found

Want to write a function that prints an error when passed a list of file names. If the file list is empty, print error "no file found", if there are more than one file, print "error more than one file found" (22 Replies)
Discussion started by: kristinu
22 Replies

5. Shell Programming and Scripting

How to give the zip file name in logrotate?

Hi, How to give file name for the zip file while compressing in logrotate... Should we need to give it in the logrotate.conf file or in the spec file...? (2 Replies)
Discussion started by: Dedeepthi
2 Replies

6. Shell Programming and Scripting

give permission to read a file

I want to give tester only the account tester to view the file /var/mail/root nobody else but him and of course the owner root w/o changing the permisions of /var/mail/root -rw-------. $ cat /var/mail/root cat: /var/mail/root: Permission denied (3 Replies)
Discussion started by: kenshinhimura
3 Replies

7. Shell Programming and Scripting

How to give permissions to an open file in vi editor?

Hi all, I have a shell script that i started editing, only in the midst of which i tried to save the changes i found that the file wasnt been provided with write/execute permissions. I later have redone the changes and saved the file- Just curious to know if there was any command wherein... (5 Replies)
Discussion started by: Pankajakshan
5 Replies

8. Shell Programming and Scripting

check for the value of one particular field and give output in a different file

hi i need to check for the value of one particular field : in the output file. the file may contain many such records as below how to ???? *** Throttled with base name + key params! : : -518594328 : les.alarm.LBS12005 : les.alarm.LBS12005 : les : lessrv1 : les : 2328 : 0... (7 Replies)
Discussion started by: aemunathan
7 Replies

9. Programming

Not able to compile Pro*c file due - give errors and points to /usr/include/.. file

I am trying to compile the pro*C file but gives errors. It says it encountered "std" while it was expecting ; , = ( $ $ORACLE_HOME/bin/proc tradewind/dataaccess/Blob.pcc Pro*C/C++: Release 10.2.0.3.0 - Production on Fri May 9 11:10:54 2008 Copyright (c) 1982, 2005, Oracle. All rights... (0 Replies)
Discussion started by: shafi2all
0 Replies

10. UNIX for Dummies Questions & Answers

how to give current date in file name?

:) I want to rename a file by giving the actual date as a file name. Is there a command for this? For example file is this: a.txt I want to copy it with a command like this: a20050510.txt (3 Replies)
Discussion started by: simurg11
3 Replies
Login or Register to Ask a Question