Operating System - HP-UX
1833598 Members
3903 Online
110061 Solutions
New Discussion

Shell script help needed.

 
sunil_34
Occasional Advisor

Shell script help needed.


Hi,

my requirement, I have multiple files .Now i want to read each line of each file.; and do the following grep in each line one after another.
grep -h 'APPLNAME= MAESTRO=' $LINE
grep -h 'ls:BEGIN' $LINE
grep -h 'ds:END' $LINE
end.

how can i do that.

Can anyone help...

regards,
Sunil.


7 REPLIES 7
Mark Grant
Honored Contributor

Re: Shell script help needed.

Sunil,

I think you are more specific about your requirements, we might be able to do what you want without ging through line by line and doing a grep. That way is really slow.

Let us know what you really want:)
Never preceed any demonstration with anything more predictive than "watch this"
sunil_34
Occasional Advisor

Re: Shell script help needed.

the requirement is that a diractory has say 12 files which are log files of different days. i ant to find the grep arguments
from the files line by line and save it in a file in that order. In short i want to
record the application name and start and end time from the log files to a different
file.
Sanjay Kumar Suri
Honored Contributor

Re: Shell script help needed.

Is this what you need?

for i in `ls`
do
grep -h "search string" $i
done

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
sunil_34
Occasional Advisor

Re: Shell script help needed.

Sanjay,

the ls argument gives me file wise i want line wise .i.e line by line for say four diff. files
Sanjay Kumar Suri
Honored Contributor

Re: Shell script help needed.

Check this

for i in `ls`
do
for j in `cat $i`
do
grep -h "search string" $j
done
done

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Manish Srivastava
Trusted Contributor

Re: Shell script help needed.

Hi,

you could do this:

for i in `ls`
do
while read line
do
grep "pattern"
some more operation
done < $i
done

Hope this fits your requirement.

manish
Robert A. Pierce
Frequent Advisor

Re: Shell script help needed.


Sunil,

If by $LINE you mean each line of each file, then you could change $LINE to FILE_PATTERN (e.g., 2004_Jun*.log), and change this:

grep -h 'APPLNAME= MAESTRO=' $LINE
grep -h 'ls:BEGIN' $LINE
grep -h 'ds:END' $LINE

to this:

grep -h -e 'APPLNAME= MAESTRO=' -e 'ls:BEGIN' -e 'ds:END' FILE_PATTERN

Does that help?