search all files for a pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers search all files for a pattern
# 1  
Old 02-13-2006
search all files for a pattern

Hi there,
I am looking for a shell script which recursively searches all the files under all the directories for a pattern specified in the script. For e.g., i am looking forward to search for the file names which contains numbers of the form 001*****.

Thanks in advance,
Naik
# 2  
Old 02-13-2006
Try this bit of code:
Code:
find <dir_you_want_to_search> -type f -exec grep -l 001[0-9][0-9][0-9][0-9][0-9] {} \;

Not thinking too clearly though. Other guys probably will give you a better solution.
# 3  
Old 02-17-2006
Quote:
Originally Posted by blowtorch
Try this bit of code:
Code:
find <dir_you_want_to_search> -type f -exec grep -l 001[0-9][0-9][0-9][0-9][0-9] {} \;

Not thinking too clearly though. Other guys probably will give you a better solution.
I'd probably do:

find <dir_you_want_search_> -type f -exec grep -lE '^001\d{5}$' {} \;

saves on some typing. =)
# 4  
Old 02-17-2006
Data Unix desired output. (Help!!!!!)

Okay I like the diff command.

diff arlog arlog.NWS | tr -d '\t ' | awk -F \| ' { print $1$2 } ' >> NEWERRORS

Next:
I would like to add: NEW TIME STAMP AT: `date` in the new file. Where can I put this portion of text. Let me explain. Since I will be searching the NEWERRORS log and it will look something like:

<NoLBAHLingotitdirectory
<****Removingarmonfilein/export/home/fininter/load
</loader/findev/log/FriFeb1716:30:21EST2006
<****Creatingarmonfilein/export/home/fininter/load
<*********LOCKBOX-GETBANKFILEFROMendeavour
<lbhap_get_bank_fileY
<CheckforLBHAPfileinendeavourdirectory
<NoLBHAPingotitdirectory
<lbahl_get_bank_fileY
<CheckforLBAHLfileinendeavourdirectory
<NoLBAHLingotitdirectory
<****Removingarmonfilein/export/home/fininter/load
</loader/findev/log/FriFeb1716:32:21EST2006
<****Creatingarmonfilein/export/home/fininter/load
<*********LOCKBOX-GETBANKFILEFROMendeavour
<lbhap_get_bank_fileY
<CheckforLBHAPfileinendeavourdirectory
<NoLBHAPingotitdirectory
<lbahl_get_bank_fileY
<CheckforLBAHLfileinendeavourdirectory
<NoLBAHLingotitdirectory
<****Removingarmonfilein/export/home/fininter/load
---

>NEWTIMESTAMPAT:WedFeb1515:25:12EST2006

>/appl/finance/findev/ar/bin/arlog.NWS:NEWTIMESTAMPAT:WedFeb1515:25:12EST2006
>NEWTIMESTAMPAT:WedFeb1515:48:16EST2006

<data> 0403-031 The fork function failed. There is not enough memory available.
<data>
<data>ftp: connect: Connection timed out.
<data>
<data>
>NEWTIMESTAMPAT:WedFeb1519:04:07EST2006
<data>
<data>ORA-06508: PL/SQL: could not find program unit being called.
<data>
<data>
>NEWTIMESTAMPAT:WedFeb1520:05:38EST2006findev:/appl/finance/findev/ar/bin: F \| ' { print $1$2 } ' >> errors <
findev:/appl/finance/findev/ar/bin: vi errors
"errors" 548 lines, 19849 characters
"errors" 548 lines, 19849 characters
1,541c1,5


Of course it doesn't look like this as of yet but I would like it to get there.
Smilie
# 5  
Old 02-23-2006
Get all lines from the arlog based on the last PREVIOUS_TIME date and time.

Quote:
Originally Posted by shephardfamily
Okay I like the diff command.

diff arlog arlog.NWS | tr -d '\t ' | awk -F \| ' { print $1$2 } ' >> NEWERRORS

Next:
I would like to add: NEW TIME STAMP AT: `date` in the new file. Where can I put this portion of text. Let me explain. Since I will be searching the NEWERRORS log and it will look something like:

<NoLBAHLingotitdirectory
<****Removingarmonfilein/export/home/fininter/load
</loader/findev/log/FriFeb1716:30:21EST2006
<****Creatingarmonfilein/export/home/fininter/load
<*********LOCKBOX-GETBANKFILEFROMendeavour
<lbhap_get_bank_fileY
<CheckforLBHAPfileinendeavourdirectory
<NoLBHAPingotitdirectory
<lbahl_get_bank_fileY
<CheckforLBAHLfileinendeavourdirectory
<NoLBAHLingotitdirectory
<****Removingarmonfilein/export/home/fininter/load
</loader/findev/log/FriFeb1716:32:21EST2006
<****Creatingarmonfilein/export/home/fininter/load
<*********LOCKBOX-GETBANKFILEFROMendeavour
<lbhap_get_bank_fileY
<CheckforLBHAPfileinendeavourdirectory
<NoLBHAPingotitdirectory
<lbahl_get_bank_fileY
<CheckforLBAHLfileinendeavourdirectory
<NoLBAHLingotitdirectory
<****Removingarmonfilein/export/home/fininter/load
---

>NEWTIMESTAMPAT:WedFeb1515:25:12EST2006

>/appl/finance/findev/ar/bin/arlog.NWS:NEWTIMESTAMPAT:WedFeb1515:25:12EST2006
>NEWTIMESTAMPAT:WedFeb1515:48:16EST2006

<data> 0403-031 The fork function failed. There is not enough memory available.
<data>
<data>ftp: connect: Connection timed out.
<data>
<data>
>NEWTIMESTAMPAT:WedFeb1519:04:07EST2006
<data>
<data>ORA-06508: PL/SQL: could not find program unit being called.
<data>
<data>
>NEWTIMESTAMPAT:WedFeb1520:05:38EST2006findev:/appl/finance/findev/ar/bin: F \| ' { print $1$2 } ' >> errors <
findev:/appl/finance/findev/ar/bin: vi errors
"errors" 548 lines, 19849 characters
"errors" 548 lines, 19849 characters
1,541c1,5


Of course it doesn't look like this as of yet but I would like it to get there.
Smilie

I am trying to put this script together and I am having grave problems doing so, this is the structure:

#!/bin/sh
# Every 6 hours

# Get all lines from the arlog based on the last PREVIOUS_TIME date and time.

PREVIOUS_TIME='DATE AND TIME: `date`' in the arlog

NEW_TIME='TODAYS DATE AND TIME: `date` ' in the arlog

#LIST OF ERRORS THAT WILL BE SEARCHED.

ERRMSG='CHECKING FOR ERRORS IN ARLOG: ERROR 9999'
ERRMSG1='0403-031 The fork function failed. There is not enough memory available.'
ERRMSG2='Login failed.'
ERRMSG3='ftp: connect: Connection timed out.'
ERRMSG4='ftp: connect: Connection refused.'
ERRMSG5='endeavour: unknown host or invalid literal address.'
ERRMSG6='ftp: Unknown host diamprodf0'
ERRMSG7='ORA-06508: PL/SQL: could not find program unit being called.'
ERRMSG8='ORA-01034: ORACLE not available.'
ERRMSG9='ORA-27101: shared memory realm does not exist.'
ERRMSG10='ORA-01005: null password given; logon denied.'
ERRMSG11='SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL.'
ERRMSG12='ORA-04068: existing state of packages has been discarded.'
ERRMSG13='ORA-04063: package body "FININTER.HAP_CUSTOMERS_INTERFACE" has errors.'
ERRMSG14='ORA-06512: IN LINE ERROR.'
ERRMSG15='ORA-01005: null password given.'

grep 'DATE STAMP: $PREVIOUS_TIME ' arlog >> TEMP_ARLOG.log

if $NEW_TIME in the arlog NOT EQUAL $PREVIOUS_TIME in arlog
then
egrep "(${ERRMSG} | ${ERRMSG1} | ${ERRMSG2} |........) from arlog.
if NO ERRORS EXIST
then
put $NEW_TIME 'No Errors To Date and time" >> arlog
else
mailx -s '$ERRORS `date` to [FMT] with message describing error or errors.
grep 'LAST TIME TRANSMISSION:' $PREVIOUS_TIME >> arlog
fi
fi

Can anyone help me? Smilie
12green
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

Pattern search multiple files

#!/usr/bin/ksh a="Run successfully" cd $APPS ls -l *.txt | while read $txt do if then cp $APPS/$txt cp $hist/$txt else rm $APPS/$txt echo "Files has been removed" fi done New in shell script please help me out Around 100 txt files in $APPS dir i want to search pattern from... (8 Replies)
Discussion started by: Kalia
8 Replies

3. Shell Programming and Scripting

Search pattern in today's files only

Hi Friends, I am in search of unix command which can search a particular pattern in all files which are created/modified today ONLY. Which is the best way to achieve this? Thanks in advance. (1 Reply)
Discussion started by: Nakul_sh
1 Replies

4. UNIX for Dummies Questions & Answers

search a pattern across all file and replace it to all files.

Hi All, HP-UX oradev3 B.11.11 U 9000/800 I have few files, which contain texts. Now I need to search a pattern across all files and replace to that pattern with new one. For example, I have following files they have, which contain something like abc@abc.com, now I need to search text acorss... (6 Replies)
Discussion started by: alok.behria
6 Replies

5. Shell Programming and Scripting

Help merging two files if search pattern true.

Hello everyone, I've been reading this forum whenever I had a problem with AWK but I can't seem to find how to solve my problem. What I would like to do is the following: I have a first file with two columns, on the first one is a certain name and in the second one, another corresponding... (4 Replies)
Discussion started by: Teroc
4 Replies

6. Shell Programming and Scripting

pattern search for multiple log files and counting

I have 10 appservers and each appserver has 4 jvms . Each of these logs is archived and stored on a nfs directory . For example the files are /logs/200907/ap1-jvm1.server.log.20090715.gz /logs/200907/ap2-jvm2.server.log.20090714.gz /logs/200908/ap1-jvm1.server.log.20090812.gz I want to... (3 Replies)
Discussion started by: gubbu
3 Replies

7. Shell Programming and Scripting

search files which doesnot match pattern ?

Hi I need a command to search files in a directory which does not match with pattern .. Plz send me this Ex : Test is directory and has some 10 files with different name all are with *.dat extension , need to search files which doesnot contain word "Dummy file". Thanks (6 Replies)
Discussion started by: madankumar
6 Replies

8. UNIX for Advanced & Expert Users

pattern search between 2 files

Afternoon guys, I have 2 files, 1.txt and 2.txt containing employee numbers. the 1st file (1.txt) is an extract from sybase with active employee numbers, the 2nd (2.txt) is a scan from the sybase log containing successfull logins *** which i have already mined and now contains only employee... (5 Replies)
Discussion started by: Jefferson333
5 Replies

9. UNIX for Dummies Questions & Answers

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (7 Replies)
Discussion started by: olapxpert
7 Replies

10. IP Networking

List files that do not match the search pattern

I need to list the files that do not match the search pattern: Example: cat file1 This is how it should work cat file2 This is why I like Unix grep -option? Unix * (or some other command) returns file1 (1 Reply)
Discussion started by: olapxpert
1 Replies
Login or Register to Ask a Question