KSH Programming to read and mail fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH Programming to read and mail fields
# 1  
Old 04-21-2009
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.
# 2  
Old 04-21-2009
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
# 3  
Old 04-21-2009
some code snips

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
# 4  
Old 04-21-2009
thanks for the help...this is what I am looking for
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Programming book should every programmer read?

hi, i want some advice on a programming book should every programmer read? (2 Replies)
Discussion started by: kaja
2 Replies

2. Shell Programming and Scripting

Can ksh read records with blank fields

I have a tab delimited file with some fields potentially containing no data. In ksh 'read' though treats multiple tabs as a single delimiter. Is there any way to change that behavior so I could have blank data too? I.e. When encountering 2 tabs it would take it as a null field? Or do I have to... (3 Replies)
Discussion started by: benalt
3 Replies

3. Shell Programming and Scripting

Read all the fields in a Loop

Hi, I have a line like A,B,C,D,E,F and I need to loop for 6 times (as many number of fields in above line) and in every loop I need to get the value into a variable. How can I do it? Pls advise! Thanks much!! (7 Replies)
Discussion started by: prvnrk
7 Replies

4. Programming

Shell programming ksh AIX - beginner

Hi! I have two shell scripts - Script1, Script2 Script1, Script2 - have return parameter Script1 - is calling Script2 in Script2 I am calling program sqlldr - if this program is called then I did not get the return parameter from Script1 Do You have any idea how can I avoid this problem. Mroki (6 Replies)
Discussion started by: mroki
6 Replies

5. Shell Programming and Scripting

ksh programming ..Any new ideas??

Hi masters I am in search for a script i am unable to write,I am not getting a proper logic .Could u pls help me ? I have a program that will create the directory named thatday date (eg :08.24.10) .This progam runs daily and creates directories according to date. Now i want to write a... (3 Replies)
Discussion started by: silu
3 Replies

6. Shell Programming and Scripting

script to read mail on a mail server

Hi All, Is there any way Unix shell script can directly read a mail on a mail server (for eg. abc@xyz.com) and save it as a text file in a unix directory ? Thanks PRKS ---------- Post updated at 08:37 AM ---------- Previous update was at 08:36 AM ---------- I am using ksh (1 Reply)
Discussion started by: PRKS
1 Replies

7. UNIX for Dummies Questions & Answers

How do I read mail in /var/spool/mail?

How can I read mail sent to /var/spool/mail? I do not have pine installed so forget about that...is there some generic utility I can use? (3 Replies)
Discussion started by: mojoman
3 Replies

8. Shell Programming and Scripting

Programming in ksh and not in bash

Hi all.... I was wondering if there is a lot of differences between /bash and ksh programming. Im learning about bash programming, but all what I had read in this forum, points me to learn more about ksh over bash. Is that right and why? Unfortunately, I can’t write ksh progs on my work,... (2 Replies)
Discussion started by: TARFU
2 Replies

9. Shell Programming and Scripting

obtaining a line number in ksh programming

Hi People, how do i obtain the line number of a ksh shell script that i am working on For example in C,when u key in __LINE__ will return u the current line number of the src code. regards wilson (1 Reply)
Discussion started by: wilsontan
1 Replies

10. Shell Programming and Scripting

Looking for ksh programming documentation

Hello, I am looking for documentation about shell programmation in ksh. I have to understand what are doing some scripts and I am rather a dummy in UNIX. What web site or book would you advice me ? Thanks. (2 Replies)
Discussion started by: Filippo
2 Replies
Login or Register to Ask a Question