KSH Programming to read and mail fields

I have a file with the following values:

File name � a.log (bulk file with 100+ lines with the similar format)
aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii|
aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii|
aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii|
aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii|
aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii|
aaaa|bbbb|cccc|dddd|eeee|ffff|gggg|hhhh|iiii|

My ksh script should do the following:

  1. Open the file
  2. Read the file and grep �gggg' field from the last 2 lines
  3. Send it to a maillist
    Please let me know the basic syntax of how to do this.

get the count of the file

count=`wc -l filename | cut -d " " -f1`
awk -F "|" -v rec=$count 'NR>=rec{print $7}' filename | mailx -s "subject" abc.com

is this what u r looking for?

cheers,
Devaraj Takhellambam

I ll give some code snips
it may help u

#!/bin/sh
var=`tail -2 file`
for i in $var; do
echo $i | cut -d "|" -f7|mailx -s "subject" abc.com
done

Or after CUT command u need to store that value to variable
and use it accordingly

thanks for the help...this is what I am looking for