Sponsored Content
Top Forums Shell Programming and Scripting Getting data from a flat file based on condition Post 302885786 by Vivekit82 on Tuesday 28th of January 2014 11:39:32 AM
Old 01-28-2014
Getting data from a flat file based on condition

Hi,

I have a flaty file from which i am fetching few columns in tablular form as below code.
Now i want to fetch the column 6 and 7 in below code only if it either of them is non zero.However below startement
Code:
awk -F, '$6==0 && $7==0{exit 1}' ${IFILE}

is not working..Not sure where is the problem.Pls help.



Code:
IFILE=/home/home1/Report1.csv
if  awk -F, '$6==0 && $7==0{exit 1}' ${IFILE}
then
  awk -F, '
    BEGIN{
     c=split("1,6,2,3,4,5,6", col)
     print "To: abc@gmail.com"
     print "Subject: Error report"
     print "MIME-Version: 1.0"
     print "Content-Type: text/html"
     print "Content-Disposition: inline\n"
     print "<HTML><TABLE border=1>"
     print "<TH>Heading 1</TH><TH>Heading 2</TH><TH>Heading 3</TH>"
     print "<TH>Heading 4</TH><TH>Heading 5</TH><TH>Heading 6</TH>"
     print "<TH>Heading 7</TH>"
    }
    NR>4 {
     printf "<TR>"
     for(i=1;i<=c;i++) printf "<TD>%s</TD>", $col[i]
     print "</TR>"
    }
    END{
      print "</TABLE></BODY></HTML>"
    } ' ${IFILE} | sendmail -t
fi


Last edited by Vivekit82; 01-28-2014 at 12:47 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sorting a flat file based on multiple colums(using character position)

Hi, I have an urgent task here. I am required to sort a flat file based on multiple columns which are based on the character position in that line. I am restricted to use the character position instead of the space and sort +1 +2 etc to do the sorting. I understand that there is a previous... (8 Replies)
Discussion started by: cucubird
8 Replies

2. Shell Programming and Scripting

Merge lines in Flat file based on first 5 characters

Hi I have the fixed width flat file having the following data 12345aaaaaaaaaabbbbbbbbbb 12365sssssssssscccccccccc 12365sssss 12367ddddddddddvvvvvvvvvv 12367 vvvvv Here the first column is length 5 second is length 10 third is length 10 if the second or third column exceeds... (3 Replies)
Discussion started by: Brado
3 Replies

3. Shell Programming and Scripting

Shell script to email based on flat file output

Hi All, I am a newbee in unix but still have written a shell script which should trigger a mail based on certain conditions but the problem is that my file is not being read. Below is the code please advise. I do not know where is it failing. Note $ and the no followed with it is the no of... (1 Reply)
Discussion started by: apoorva
1 Replies

4. Shell Programming and Scripting

Load data from a flat file to oracle.

I have a flat file with records like Header 123 James Williams Finance2000 124 Pete Pete HR 1500 125 PatrickHeather Engg 3000 Footer The structure is: Eno:4 characters Name:8 characters Surname : 9 characters Dept:7 characters Sal:4characters These are sample... (1 Reply)
Discussion started by: Shivdatta
1 Replies

5. UNIX for Dummies Questions & Answers

Normalize Data and write to a flat file

All, Can anyone please help me with the below scenario. I have a Flat file of the below format. ID|Name|Level|Type|Zip|MAD|Risk|Band|Salesl|Dealer|CID|AType|CValue|LV|HV|DCode|TR|DU|NStartDate|UserRole|WFlag|EOption|PName|NActivationDate|Os|Orig|Cus|OType|ORequired|DType 03|... (10 Replies)
Discussion started by: sp999
10 Replies

6. Shell Programming and Scripting

To read a flat file containing XML data

I have a file something like this:aaaa.xml content of the file is 0,<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <storeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <s> <BRANCH_NO>3061</BRANCH_NO> <BRANCH_NAME>GREEN EXPRESS</BRANCH_NAME> ... (4 Replies)
Discussion started by: kmanivan82
4 Replies

7. UNIX for Dummies Questions & Answers

Deleting the unwanted data based on condition

hi i have my input data like this aaa bbb ccc asa dff nmj mnj saa dff oik aax cdx saa oik asq sdf dssi want my output file to be like this mnj saa dff oik aax cdx saa oiki want to retain only those lines which will have oik just below them and i want oik to be as next column to those... (1 Reply)
Discussion started by: anurupa777
1 Replies

8. Shell Programming and Scripting

Sort based on positions in flat file

Hello, For example: 12........6789101112..............20212223242526..................50 ( Positions) LName FName DOB (Lastname starts from 1 to 6 , FName from 8 to 15 and date of birth from 21 to29) CURTIS KENNETH ... (5 Replies)
Discussion started by: duplicate
5 Replies

9. Shell Programming and Scripting

Dynamically prepare the condition using flat file sdata

I have a file in which the data looks like A,B My output should be T1.A=T2.A AND T1.B=T2.B If my input is A,B,C My output should be T1.A=T2.A AND T1.B=T2.B AND T1.C=T2.C Currently I am automating my databae script and strucked with this part.Not able to search the... (2 Replies)
Discussion started by: bikky6
2 Replies

10. Shell Programming and Scripting

Adding data from a file based on some condition

I collect data in a file in below format(Month Day Year Size) in RedHat Linux. Now i want to calculate the data size date wise. As i code shell script after long time, i forgot the features and syntax. Can anyone help me regard this please. Feb 8 2014 15 Feb 10 2014 32 Feb 10 2014 32 Feb 12... (2 Replies)
Discussion started by: makauser
2 Replies
MIME::Field::ContType(3)				User Contributed Perl Documentation				  MIME::Field::ContType(3)

NAME
MIME::Field::ContType - a "Content-type" field DESCRIPTION
A subclass of Mail::Field. Don't use this class directly... its name may change in the future! Instead, ask Mail::Field for new instances based on the field name! SYNOPSIS
use Mail::Field; use MIME::Head; # Create an instance from some text: $field = Mail::Field->new('Content-type', 'text/HTML; charset="US-ASCII"'); # Get the MIME type, like 'text/plain' or 'x-foobar'. # Returns 'text/plain' as default, as per RFC 2045: my ($type, $subtype) = split('/', $field->type); # Get generic information: print $field->name; # Get information related to "message" type: if ($type eq 'message') { print $field->id; print $field->number; print $field->total; } # Get information related to "multipart" type: if ($type eq 'multipart') { print $field->boundary; # the basic value, fixed up print $field->multipart_boundary; # empty if not a multipart message! } # Get information related to "text" type: if ($type eq 'text') { print $field->charset; # returns 'us-ascii' as default } PUBLIC INTERFACE
boundary Return the boundary field. The boundary is returned exactly as given in the "Content-type:" field; that is, the leading double-hyphen ("--") is not prepended. (Well, almost exactly... from RFC 2046: (If a boundary appears to end with white space, the white space must be presumed to have been added by a gateway, and must be deleted.) so we oblige and remove any trailing spaces.) Returns the empty string if there is no boundary, or if the boundary is illegal (e.g., if it is empty after all trailing whitespace has been removed). multipart_boundary Like "boundary()", except that this will also return the empty string if the message is not a multipart message. In other words, there's an automatic sanity check. type Try real hard to determine the content type (e.g., "text/plain", "image/gif", "x-weird-type", which is returned in all-lowercase. A happy thing: the following code will work just as you would want, even if there's no subtype (as in "x-weird-type")... in such a case, the $subtype would simply be the empty string: ($type, $subtype) = split('/', $head->mime_type); If the content-type information is missing, it defaults to "text/plain", as per RFC 2045: Default RFC 2822 messages are typed by this protocol as plain text in the US-ASCII character set, which can be explicitly specified as "Content-type: text/plain; charset=us-ascii". If no Content-Type is specified, this default is assumed. Note: under the "be liberal in what we accept" principle, this routine no longer syntax-checks the content type. If it ain't empty, just downcase and return it. NOTES
Since nearly all (if not all) parameters must have non-empty values to be considered valid, we just return the empty string to signify missing fields. If you need to get the real underlying value, use the inherited "param()" method (which returns undef if the parameter is missing). SEE ALSO
MIME::Field::ParamVal, Mail::Field AUTHOR
Eryq (eryq@zeegee.com), ZeeGee Software Inc (http://www.zeegee.com). David F. Skoll (dfs@roaringpenguin.com) http://www.roaringpenguin.com perl v5.12.1 2008-06-30 MIME::Field::ContType(3)
All times are GMT -4. The time now is 02:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy