The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How do I read mail in /var/spool/mail? mojoman UNIX for Dummies Questions & Answers 3 12-05-2008 04:48 PM
How do I read/find/replace fields in a csv datafile? MrCarter UNIX for Dummies Questions & Answers 9 06-20-2008 11:15 AM
How to read and compare multiple fields in a column at the same time ahjiefreak Shell Programming and Scripting 1 06-19-2008 12:08 PM
script to read from mail misenkiser Shell Programming and Scripting 0 10-03-2006 09:07 AM
To Read a text file using shell Programming sandytul UNIX for Dummies Questions & Answers 1 04-11-2001 12:15 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-21-2009
shivacbz shivacbz is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
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 (permalink)  
Old 04-21-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
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 (permalink)  
Old 04-21-2009
msvinaykumar msvinaykumar is offline
Registered User
  
 

Join Date: Aug 2006
Posts: 3
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 (permalink)  
Old 04-21-2009
shivacbz shivacbz is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 8
thanks for the help...this is what I am looking for
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0