Getting data in table form


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Getting data in table form
# 1  
Old 01-23-2014
Getting data in table form

Hi,

I have a csv file from which i am fetching few columns as below:

Code:
 
IFILE=/home/home1/Report1.csv
OFILE=/home/home1/`date +"%m%d%y%H%M%S"`.dat
if [ -r $IFILE ]  #Checks if file exists and readable
then
awk -F "," '(NR>4) {print $1,$6,$2,$3,$4,$5,$6}' ${IFILE} >> ${OFILE}
fi
cat $OFILE | mail -s "Error report" abc@gmail.com

I want the output in tabular form
# 2  
Old 01-23-2014
Could you please let us know the input and expected output for same.


Thanks,
R. Singh
# 3  
Old 01-23-2014
I/P:

csv file:

Code:
column1  column 2  column 3
abc         def          ghi

Output should be in tabular form like we have in excel..use table format option.
It should have lines forming tables and in that data should be there

Last edited by Vivekit82; 01-23-2014 at 05:11 PM.. Reason: code tags
# 4  
Old 01-23-2014
Try to add
Code:
awk '...' OFS=";" ...

or
Code:
OFS="\t"

# 5  
Old 01-23-2014
How about this:

Code:
IFILE=/home/home1/Report1.csv
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

This User Gave Thanks to Chubler_XL For This Post:
# 6  
Old 01-24-2014
Thanks all.
The last html code works..
I just need to put one more condition ie mail should be sent only if column 6 and column 7 is not equal to 0. what needs to be done for that..
Thanks.
# 7  
Old 01-24-2014
This will send the email if ANY row has non-zero in BOTH field 6 and 7:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

JSON structure to table form in awk, bash

Hello guys, I want to parse a JSON file in order to get the data in a table form. My JSON file is like this: { "document":{ "page": }, { "column": } ] }, { ... (6 Replies)
Discussion started by: Gescad
6 Replies

2. Shell Programming and Scripting

Transpose Data form Different form

HI Guys, I have data in File A.txt RL03 RL03_A_1 RL03_B_1 RL03_C_1 RL03 -119.8 -119.5 -119.5 RL07 RL07_A_1 RL07_B_1 RL07_C_1 RL07 -119.3 -119.5 -119.5 RL15 RL15_A_1 RL15_C_1 RL15 -120.5 -119.4 RL16... (2 Replies)
Discussion started by: asavaliya
2 Replies

3. UNIX for Dummies Questions & Answers

Put data into tabular form

Hi I am having a file which is required to be presented in the under-noted output form. Please suggest. Input: Kapil: apple 4 banana 6 cherry 0 Manoj: apple 13 banana cheery 2 Output: apple banana cherry Kapil: 4 6 0 Manoj: 13 2 Thanks in... (4 Replies)
Discussion started by: vanand420
4 Replies

4. Shell Programming and Scripting

Converting form field to table format

May data Name = Andi Address = none Phone = 82728 Name = Peter Address = none Phone = 98799 The expected output Name,Address,Phone Andi,none,82728 Peter,none,98799 what i have done (6 Replies)
Discussion started by: before4
6 Replies

5. UNIX for Dummies Questions & Answers

Posting data to a form using curl

Hello all. I have an incredible number of servers that I need to change a parameter on using a web interface. I'd like to be able to do this via curl, but I'm having some trouble. I filled out the form and hit update while snooping (tcpdump) my interface. That gave the the following as what is... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

6. Shell Programming and Scripting

convert one form of xml data to other

I would like to convert one form of xml tag data to another <DescriptionList> <DescriptionExt language="en" shortDesc="ITALIAN SAUSAGE SUB" longDesc="" sizeDesc="" smallImage="Pictures\sub-italian-sausage.png" largeImage="" forceImageUpdate="yes" /> ... (1 Reply)
Discussion started by: saisus
1 Replies

7. UNIX for Dummies Questions & Answers

changing data into matrix form

Hi, I have a file whose structure is like this 7 7 1 2 3 4 5 1 3 4 8 6 1 4 5 6 0 2 6 8 3 8 2 5 7 8 0 5 7 9 4 1 3 8 0 2 2 3 5 6 8 basically first two row tell the number of rows and column but the data following them are not arranged in that format. now i want to create another... (1 Reply)
Discussion started by: g0600014
1 Replies

8. Shell Programming and Scripting

help on formatting output (Table Form)

Data in File ABC:DEFGHI:123 ABCZYE:DEFI:123 ABCFGD:DEF:123 ABCEERRRRR:DEFGHI:123 Expected Format 1 ABC DEFGHIFE 123 2 ABCZYE DEFI 123 3 ABCFGD DEF 123 4 ABCEERRRRR DEFGHI 123 However when i enter the following... (2 Replies)
Discussion started by: blurboy
2 Replies

9. UNIX for Dummies Questions & Answers

data form

I am user Of linux 9.0 Operating System and I had data form unix Operating system and I am not abel to open it in linux 9.0 Please tell me how can i use unix data in linux . (3 Replies)
Discussion started by: harsh_guru
3 Replies
Login or Register to Ask a Question