grep and loop files

Hi ,

  1. I want to grep two or three lines from a set of files and put the grepped lines into again a set of files.like
    file1-greppedfile1
    file2-greppedfile2

then again do some format to the grepped files with sed or awk then create another set of files.
How can I do this in loop?

2.I want to grep a date within a file.The date is at almost end of the file
but there are also some dates above the last date format which i have to grep.

Help will be appreciated...

Thanks

Do not post questions without trying to solve the problem yourself based on your understanding. Post what have you tried so far and where exactly are you stuck?

Your second problem looks like you want to get from a file the last line containing a date. If so, then try something like

grep date file | tail -n 1 

I'm afraid I don't understand your first problem; give us an example?

Hi,
I am beginner in shell scripting.I have done the grep for one file like

grep -i 'abcd' from file1>file2
grep '1234' from file1>>file2

then by awk I have divided '1234/234' and appended file2>file3.

This I have to do it for 5 files.
for each file there must be seperate result file.I can do it manually but this is to be run like a job.
I hope you got my my problem..

Alrighty, this might not be the most efficient way of doing this, but you can give this a try..

suppose you have file1, file2,file3,file4 and so on to grep,

arg1=abcd
arg2=1234
for i in file*
do
grep -i $arg1 $i >$arg1_$i
grep -j $arg2 $i >$arg2_$i
done

find . -empty | xargs rm

This should do the trick.