Sponsored Content
Top Forums Shell Programming and Scripting Search if file exists for a file pattern stored in array Post 302935914 by 100bees on Friday 20th of February 2015 07:53:36 AM
Old 02-20-2015
Search if file exists for a file pattern stored in array

Hi experts,

I have two arrays one has the file paths to be searched in , and the other has the files to be serached.For eg
searchfile.dat will have
Code:
abc303
xyz123

i have to search for files that could be abc303*.dat or for that matter any extension . abc303*.dat.gz

The following code doesnt work if i give * , it works only if i give the exact file name to be searched in the searchfile.dat
Code:
#!/usr/bin/ksh
set -A filearray $(cat searchfile.dat)
fp1=/home/user/fp1
fp2=/home/user/fp2
fp3=/home/user/fp3
 
set -A filepath $fp1 $fp2 $fp3
i=0
j=0
 while [[ $i -lt ${#filearray[@]}  ]];do
 while [[ $j -lt ${#filepath[@]} ]];do
 found=0
 if [[ -a  "${filepath[$j]}/${filearray[$i]}"\* ]]; then
 echo ${filepath[$j]}/${filearray[$i]} "found"



Moderator's Comments:
Mod Comment Please use code tags!!

Last edited by 100bees; 02-20-2015 at 09:07 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Prase a file and stored the result to an array

Dear all , I have a file whose content has the following format: jboss.web:type=ThreadPool,name=AAAA jboss.web:type=ThreadPool,name=BBBB How can I parse this file to get the value of the name of each line (AAAA , BBBB) and store the result to an array ? (array = AAAA , array = BBBB).... (4 Replies)
Discussion started by: youareapkman
4 Replies

2. 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

3. Shell Programming and Scripting

Grep pattern from different file and display if it exists in the required file

Hi, I have two files say xxx.txt and yyy.txt. xxx.txt is with list of patterns within double quotes. Eg. "this is the line1" "this is the line2" The yyy.txt with lot of lines. eg: "This is a test message which contains rubbish information just to fill the page which is of no use. this is... (3 Replies)
Discussion started by: abinash
3 Replies

4. UNIX for Dummies Questions & Answers

Need help finding a file where a pattern exists and the file has a timestamp

So, I know how to do some of this stuff on an individual level, but I'm drawing a blank as to how to put it all together. I have a pattern that I'm looking for in a log file. The log file I know came in yesterday, so I want to limit the search to that day's listing of files. How would I do... (5 Replies)
Discussion started by: kontrol
5 Replies

5. UNIX for Dummies Questions & Answers

Searching for a pattern from filenames stored in a file

Hi, I have got some 10 filenames stored in a file or displayed in the console as a result of some query i made.. Now I need to open each of these files and search for a pattern in these 10 files.. Can someone help me with this? Thanks, Jean (9 Replies)
Discussion started by: jeanjkj
9 Replies

6. Shell Programming and Scripting

Want to Insert few lines which are stored in some file before a pattern in another file

Hello, I have few lines to be inserted in file_lines_to_insert. In another file final_file, I have to add lines from above file file_lines_to_insert before a particular pattern. e.g. $ cat file_lines_to_insert => contents are abc def lkj In another file final_file, before a... (6 Replies)
Discussion started by: nehashine
6 Replies

7. Shell Programming and Scripting

Check for Pattern if exists write to file

Hi ! All I just want to search and write to new file if pattern is found in text file following are my text files by which I want to search Month and last column number my text file1 15-Jan-2011 25 ARTS 1255 125 125 178 198 15-Jan-2011 25 ARTS 1255 125 125 178 198 15-Jan-2011 25... (3 Replies)
Discussion started by: nex_asp
3 Replies

8. Shell Programming and Scripting

Search for a pattern that exists in the codebase

Hello everyone, I want to search for a specific pattern in the entire codebase that exists. Pattern: I need to find wherever there is a harcoded value "Vxxxx" and "GCxxxx" exists in the perl scripts and shell scripts. (where xxxx will be always number) I need the script name and the value... (1 Reply)
Discussion started by: filter
1 Replies

9. Shell Programming and Scripting

How to search a filename stored in a variable using a pattern?

hi, i have a variable which contains some file names delimited by a single space. FNAME="s1.txt s2.lst s3.cvs s4.lst" i have another variable that contains a pattern FILE_PATTERN="*.lst" i want to take the filenames from FNAME variable and assign each file name in to an array say for... (8 Replies)
Discussion started by: Little
8 Replies

10. UNIX for Beginners Questions & Answers

If file pattern exists in directory then continue

he below looks in $dir for any pattern of fileone. As is, it executes but only returns File found if the exact format in the script exsists. Why isn't a pattern of fileone being looked for and if it is in $dir, File found. I think that is what should happen. Thank you :). dir=/path/to if... (5 Replies)
Discussion started by: cmccabe
5 Replies
Font::TTF::Segarr(3pm)					User Contributed Perl Documentation				    Font::TTF::Segarr(3pm)

NAME
Font::TTF::Segarr - Segmented array DESCRIPTION
Holds data either directly or indirectly as a series of arrays. This class looks after the set of arrays and masks the individual sub- arrays, thus saving a class, we hope. INSTANCE VARIABLES
All instance variables do not start with a space. The segmented array is simply an array of segments Each segment is a more complex affair: START In terms of the array, the address for the 0th element in this segment. LEN Number of elements in this segment VAL The array which contains the elements METHODS
Font::TTF::Segarr->new($size) Creates a new segmented array with a given data size $s->fastadd_segment($start, $is_sparse, @dat) Creates a new segment and adds it to the array assuming no overlap between the new segment and any others in the array. $is_sparse indicates whether the passed in array contains "undef"s or not. If false no checking is done (which is faster, but riskier). If equal to 2 then 0 is considered undef as well. Returns the number of segments inserted. $s->add_segment($start, $overwrite, @dat) Creates a new segment and adds it to the array allowing for possible overlaps between the new segment and the existing ones. In the case of overlaps, elements from the new segment are deleted unless $overwrite is set in which case the elements already there are over-written. This method also checks the data coming in to see if it is sparse (i.e. contains undef values). Gaps cause new segments to be created or not to over-write existing values. $s->tidy Merges any immediately adjacent segments $s->at($addr, [$len]) Looks up the data held at the given address by locating the appropriate segment etc. If $len > 1 then returns an array of values, spaces being filled with undef. $s->remove($addr, [$len]) Removes the item or items from addr returning them as an array or the first value in a scalar context. This is very like "at", including padding with undef, but it deletes stuff as it goes. $s->copy Deep copies this array $s->copy_seg($seg) Creates a deep copy of a segment BUGS
No known bugs. AUTHOR
Martin Hosken Martin_Hosken@sil.org. See Font::TTF::Font for copyright and licensing. perl v5.10.1 2009-01-21 Font::TTF::Segarr(3pm)
All times are GMT -4. The time now is 05:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy