To find 3 patterns in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To find 3 patterns in a file
# 1  
Old 06-04-2009
To find 3 patterns in a file

hy i have a requirement in which my script needs to find 3 patterns in a file and if any pattern is missing it should sent a mail

Patterns
Code:
Interval60min_Daily_readings$a.txt
Interval_Daily_readings$a.txt
Daily_readings$a.txt


Basically i want to test for the above Patterns in the file generated by the script .How shall i implement this logic in my script


Below my script

Code:
#!/bin/ksh

rm -rf all_rep_files.txt
TZ=`date +%Z`+24 ;a=`date +"%m%d%Y"`
echo $a

for i in 616498114_ReliantES 799530915_ReliantRS  
do
        echo "user odad odd" > ftp.txt
        echo "prompt" >> ftp.txt
        echo "cd $i" >> ftp.txt
        echo "ls -ltr" >> ftp.txt
        echo "bye" >> ftp.txt
        ftp -nv ftp.oncor.com < ftp.txt > ftplog_$i.log
        echo "Completed for $i"
        cat ftplog_$i.log | egrep "Interval_Daily_readings$a|Daily_readings$a|Interval60min_Daily_readings$a" > ftplog_$i.txt
        echo "**********************CONTENTS OF REP $i*****************************" >> all_rep_files.txt
        cat ftplog_$i.txt >> all_rep_files.txt
        rm -rf ftplog_$i.log

########here only i need to test in the file ftplog_$i.txt for those patterns and if not found should mail the pattern#############


Last edited by ali560045; 06-04-2009 at 04:09 AM..
# 2  
Old 06-04-2009
Code:
If [ `wc -l ftplog_$i.log | cut -d" "  -f1` -lt 3 ]; then
mailx -s "Missing file" blah blah blha
exit 1
else
something
fi


-Devaraj Takhellambam
# 3  
Old 06-05-2009
devtakh's solution tells you if the file has less than three lines. Maybe this is all you need and I have misunderstood the situation, but I would use grep(1) to check for the occurrence each pattern, e.g.
Code:
for pattern in pattern0 pattern1 pattern2
do
    grep -q $pattern $file || mail -s "No $pattern in $file" someone@somewhere
done

Note that this will send a separate email for each missing pattern -- I don't know if that's what you want.

N.B. Something similar has been asked before:
https://www.unix.com/unix-dummies-que...ll-script.html
but I'm not convinced about the answer there -- it will work as long as all three patterns are on the same line, but maybe that's a good assumption for you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to form a correct syntax to sift out according to complementary patterns with 'find'?

I need to find all files and folders containing keyword from the topmost directory deep down the tree but omitting all references to keyword in web-search logs and entries, i.e. excluding search and browsing history made using web-browser1, web-browser2, web-browser3, (bypassing all entries of the... (8 Replies)
Discussion started by: scrutinizerix
8 Replies

2. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Find matched patterns and print them with other patterns not the whole line

Hi, I am trying to extract some patterns from a line. The input file is space delimited and i could not use column to get value after "IN" or "OUT" patterns as there could be multiple white spaces before the next digits that i need to print in the output file . I need to print 3 patterns in a... (3 Replies)
Discussion started by: redse171
3 Replies

4. Shell Programming and Scripting

Find matched patterns in multiple files

Hi, I need help to find matched patterns in 30 files residing in a folder simultaneously. All these files only contain 1 column. For example, File1 Gr_1 st-e34ss-11dd bt-wwd-fewq pt-wq02-ddpk pw-xsw17-aqpp Gr_2 srq-wy09-yyd9 sqq-fdfs-ffs9 Gr_3 etas-qqa-dfw ddw-ppls-qqw... (10 Replies)
Discussion started by: redse171
10 Replies

5. Shell Programming and Scripting

Find common patterns in multiple file

Hi, I need help to find patterns that are common or matched in a specified column in multiple files. File1.txt ID1 555 ID23 8857 ID4 4454 ID05 555 File2.txt ID74 4454 ID96 555 ID322 4454 (4 Replies)
Discussion started by: redse171
4 Replies

6. Shell Programming and Scripting

Find patterns and filter the text

I need to filter the text in between two patterns and output that to a different file. Please help me how to do it. Ex: ............. <some random text> ............. Pattern_1 <Few lines that need to be output to different file> Pattern_2 ................ ............... <more text in... (4 Replies)
Discussion started by: metturr
4 Replies

7. UNIX for Dummies Questions & Answers

Find diff between two patterns in two files and append

Hi, I'm a newbie at programming in Unix, and I seem to have a task that is greater than I can handle. Trying to learn awk by the way (but in the end, i just need something that works). My goal is to compare two files and output the difference between the two. I've been reading, and I think I... (5 Replies)
Discussion started by: legato22
5 Replies

8. UNIX for Dummies Questions & Answers

Find records with matching patterns

Hi, I need to find records with a search string from a file. Search strings are provided in a file. For eg. search_String.txt file is like below chicago mexico newark sanhose and the file from where the records need to be fetched is given below src_file:... (1 Reply)
Discussion started by: sbhuvana20
1 Replies

9. Shell Programming and Scripting

Find files that do not match specific patterns

Hi all, I have been searching online to find the answer for getting a list of files that do not match certain criteria but have been unsuccessful. I have a directory that has many jpg files. What I need to do is get a list of the files that do not match both of the following patterns (I have... (21 Replies)
Discussion started by: nikos-koutax
21 Replies

10. Shell Programming and Scripting

Searching patterns in 1 file and deleting all lines with those patterns in 2nd file

Hi Gurus, I have a file say for ex. file1 which has 3500 lines in it which are different account numbers and another file (file2) which has 230000 lines in it. I want to read all the lines in file1 and delete all those lines from file2 which has that same pattern as in file1. I am not quite... (4 Replies)
Discussion started by: toms
4 Replies
Login or Register to Ask a Question