Pattern matching for file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern matching for file
# 1  
Old 06-20-2008
Pattern matching for file

Hi All,

I'm new to perl,
My requirement is to check if particular file exists.
e.g. filename.txt, filename1.txt, filename2.txt etc

I tried the below code:-

my $var1 = "filename.txt"

if ( -e ($var1 = ~ /file\w/))
{
print "File found \n";
}
else
{ print "File not found \n";
}

I'm getting o/p as “File not found” Smilie, please let me know what is wrong in my code.

Thanks in Adv.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Big pattern file matching within another pattern file in awk or shell

Hi I need to do a patten match between files . I am new to shell scripting and have come up with this so far. It take 50 seconds to process files of 2mb size . I need to tune this code as file size will be around 50mb and need to save time. Main issue is that I need to search the pattern from... (2 Replies)
Discussion started by: nitin_daharwal
2 Replies

2. Shell Programming and Scripting

Take only lastest file matching the pattern

Hi All , I have some fille names in a file which are sorted according to date. for example file1_123.log 23 Jul 0Kb file2_123.log 22 Jul 2Kb file3_123.log 20 Jul 0Kb file1_456.log 24 Jul 2Kb file2_678.log 22 Jul 0Kb file2_678.log 21 Jul 2Kb here 123 is a... (2 Replies)
Discussion started by: LoneRanger
2 Replies

3. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

4. Shell Programming and Scripting

Get matching string pattern from a file

Hi, file -> temp.txt cat temp.txt /home/pradeep/123/a_asp.html /home/pradeep/123/a_asp1.html /home/pradeep/435/a_asp2.html /home/pradeep/arun/abc/a_dfr.html /home/pradeep/arun/123/a_kir.html /home/pradeep/123/arun/a_dir.html .... .... .. i need to get a_*.html(bolded strings... (4 Replies)
Discussion started by: pradebban
4 Replies

5. Shell Programming and Scripting

Help with matching pattern inside a file

I have a huge file that has roughly 30304 lines. I need to extract specific info from that file. For example, Box 1 > *aaaaaaaajjjj* > hbbvjvj > jdnnfddllll > *dgdfhfekwjh* Box 2 > *aaaaaaa'aj'jjj* > dse hkjuejef bfdw > dyeee > dsewq > *dgdfhfekwjh* >feweiuei Box 3 > *aaaa"aaaaj"jjj* >... (25 Replies)
Discussion started by: Ernst
25 Replies

6. UNIX for Dummies Questions & Answers

PERL pattern matching in a file

Hi Gurus, I have a file like below.. I have to match each with predefined pattern. If matches then have to write the entire record to a separate file. If not make the value as NULL and write the entire record into another file. | is the delimiter ravi123|2344|M R123Vi|2345|F... (8 Replies)
Discussion started by: pvksandeep
8 Replies

7. Shell Programming and Scripting

check if file exists with pattern matching

Hello friends, I am writing a simple shell script which will copy one particular type of files to backup folder if files exists. If files doesn't exists, mv command should not be executed. My file pattern is like wcm-spider-maestro.log.2009-07-15, wcm-spider-maestro.log.2009-07-16 etc.. I... (6 Replies)
Discussion started by: sreenu.shell
6 Replies

8. Programming

File Pattern Matching C++

Hi, I have large files with fixed length fields or fields seperated by delimeter. I would like to do validation on some or all fields to check for numeric or date or characters etc.. I would like to write this in C++. Please let me know if any one have any ideas on this. Thanks for all... (2 Replies)
Discussion started by: rameshmelam
2 Replies

9. UNIX for Dummies Questions & Answers

How can you delete records in a file matching a pattern?

I am curious if the following can be done in a file in unix. Let's say I have a flat file with the following data AAA,12,2,,,, BBB,3,1,,,, CCC,,,,, DDD,2,,,,, SQQ,,,,, ASJ,,3,5 I only want to capture the data with values into a new file. If the data contains the pattern ,,,,, as in... (2 Replies)
Discussion started by: mode09
2 Replies

10. Programming

getting file words as pattern matching

Sir, I want to check for the repation of a user address in a file i used || as my delimiter and want to check repetaip0n of the address that is mailid and then i have to use IMAP and all. How can i do this... I am in linux ...and my file is linux file. ... (5 Replies)
Discussion started by: arunkumar_mca
5 Replies
Login or Register to Ask a Question
getopt(1)							   User Commands							 getopt(1)

NAME
getopt - parse command options SYNOPSIS
set -- ` getopt optstring $ * ` DESCRIPTION
The getopts command supersedes getopt. For more information, see NOTES below. getopt is used to break up options in command lines for easy parsing by shell procedures and to check for legal options. optstring is a string of recognized option letters; see getopt(3C). If a letter is followed by a colon (:), the option is expected to have an argument which may or may not be separated from it by white space. The special option - is used to delimit the end of the options. If it is used explicitly, getopt recognizes it; otherwise, getopt generates it; in either case, getopt places it at the end of the options. The posi- tional parameters ($1 $2 ...) of the shell are reset so that each option is preceded by a - and is in its own positional parameter; each option argument is also parsed into its own positional parameter. EXAMPLES
Example 1 Processing the arguments for a command The following code fragment shows how one might process the arguments for a command that can take the options -a or -b, as well as the option -o, which requires an argument: set -- `getopt abo: $*` if [ $? != 0 ] then echo $USAGE exit 2 fi for i in $* do case $i in -a | -b) FLAG=$i; shift;; -o) OARG=$2; shift 2;; --) shift; break;; esac done This code accepts any of the following as equivalent: cmd -aoarg filename1 filename2 cmd -a -o arg filename1 filename2 cmd -oarg -a filename1 filename2 cmd -a -oarg -- filename1 filename2 ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | |CSI |enabled | +-----------------------------+-----------------------------+ SEE ALSO
Intro(1), getopts(1), getoptcvt(1), sh(1), shell_builtins(1), getopt(3C), attributes(5) DIAGNOSTICS
getopt prints an error message on the standard error when it encounters an option letter not included in optstring. NOTES
getopt will not be supported in the next major release. For this release a conversion tool has been provided, namely, getoptcvt. For more information, see getopts(1) and getoptcvt(1). Reset optind to 1 when rescanning the options. getopt does not support the part of Rule 8 of the command syntax standard (see Intro(1)) that permits groups of option-arguments following an option to be separated by white space and quoted. For example, cmd -a -b -o "xxx z yy" filename is not handled correctly. To correct this deficiency, use the getopts command in place of getopt. If an option that takes an option-argument is followed by a value that is the same as one of the options listed in optstring (referring to the earlier EXAMPLES section, but using the following command line: cmd -o -a filename getopt always treats it as an option-argument to -o; it never recognizes -a as an option. For this case, the for loop in the example shifts past the filename argument. SunOS 5.11 7 Jan 2000 getopt(1)