Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Convert text file data into XL file format Post 302999882 by RavinderSingh13 on Thursday 29th of June 2017 08:13:59 AM
Old 06-29-2017
Hello scriptor,

could you please try following and let me know if this helps you.
Code:
awk -v Date=$(date +%d) -v Month=$(date +%m) -v Year=$(date +%Y) 'BEGIN{print "Date         stat1 stat2 stat3 stat4 stat5";split("Jan,Feb,Mar,Apr,may,Jun,Jul,Aug,Sept,Oct,Nov,Dec", array,",");MON=array[sprintf("%d",Month)];VAL=Date"-"MON"-"Year} NR==1{print VAL,$0;next} {printf("%"length(VAL)+1"s%s\n","",$0)}'  Input_file  | mailx -s"test_email"  chumma@chumma.com

EDIT: Adding a non-one liner form of solution too here.
Code:
awk -v Date=$(date +%d) -v Month=$(date +%m) -v Year=$(date +%Y) 'BEGIN{
                                                                        print "Date         stat1 stat2 stat3 stat4 stat5";
                                                                        split("Jan,Feb,Mar,Apr,may,Jun,Jul,Aug,Sept,Oct,Nov,Dec", array,",");
                                                                        MON=array[sprintf("%d",Month)];
                                                                        VAL=Date"-"MON"-"Year
                                                                       }
                                                                  NR==1{
                                                                        print VAL,$0;
                                                                        next
                                                                       }
                                                                       {
                                                                        printf("%"length(VAL)+1"s%s\n","",$0)
                                                                       }
                                                                 '  Input_file | mailx -s"test_email" chumma@chumma.com

EDIT2: Adding a little more modified solution where no hard coded first heading.
Code:
awk -v Date=$(date +%d) -v Month=$(date +%m) -v Year=$(date +%Y) 'BEGIN{
                                                                        split("Jan,Feb,Mar,Apr,may,Jun,Jul,Aug,Sept,Oct,Nov,Dec", array,",");
                                                                        MON=array[sprintf("%d",Month)];
                                                                        VAL=Date"-"MON"-"Year
                                                                        printf("%s%"length(VAL)+1"s %s %s %s %s\n","Date","stat1","stat2","stat3","stat4","stat5");
                                                                       }
                                                                  NR==1{
                                                                        print VAL,$0;
                                                                        next
                                                                       }
                                                                       {
                                                                        printf("%"length(VAL)+1"s%s\n","",$0)
                                                                       }
                                                                 '  Input_file  | mailx -s"test_email"  chumma@chumma.com

Thanks,
R. Singh

Last edited by RavinderSingh13; 06-29-2017 at 09:38 AM.. Reason: Adding a non-one liner form of solution too successfully here.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

write data into a text file in bold format

Hi, can anyone help to write data into a text file in bold format and rollback to actual format. Thanks, Regards, Milton Y. (1 Reply)
Discussion started by: miltony
1 Replies

2. UNIX for Advanced & Expert Users

Convert UTF8 Format file to ANSI format

:) Hi i am trying to convert a file which is in UTF8 format to ANSI format i tried to use the function ICONV but it is throwing error Function i used it as $ iconv -f UTF8 -t ANSI filename Error iam getting is NOT Supported UTF8 to ANSI please some help me out on this.........Let me... (1 Reply)
Discussion started by: rajreddy
1 Replies

3. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

4. Shell Programming and Scripting

Convert comma text file to Column in html format

I am trying to generate a report with below file : File1 : EQADM,edrtere9-phys,8122caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere11-phys,8227caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere3-phys,822caef0,gpatmon,/bin/ksh,nuten Erick can you help me convert it to html and add... (9 Replies)
Discussion started by: sriram003
9 Replies

5. Programming

awk script to convert a text file into csv format

hi...... thanks for allowing me to start a discussion i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database.. the input text file is as follows:- USB History Dump by nabiy (c)2008 (1) --- Kingston DataTraveler 130 USB... (2 Replies)
Discussion started by: certteam
2 Replies

6. UNIX for Dummies Questions & Answers

How to convert a text file into tab delimited format?

I have a text file that made using text editor in Ubuntu. However the text file is not being recognized as space or tab delimited, the formatting seems to be messed up. How can I convert the text file into tab delimited format? (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

Need a unix script to convert date into Julian format in a text file

The 6th & 7th column of the text files represents date & time. I need this to be converted in julian format using command "date +%s -d <date>". I know the command, but dont know how to use it on the script 0 dbclstr-b IXT_Web Memphis_Prod_SQL_Full Memphis-Prod-SQL-Full-Application-Backup... (4 Replies)
Discussion started by: ajiwww
4 Replies

8. Shell Programming and Scripting

Convert text file to HTML tabular format.

Please provide script/commands to convert text file to HTML tabular format. No need of styles and colours, just output and a heading in table is required. Output file will be send via email and will be seen from outlook. (script required without using awk). output file content: (sar... (7 Replies)
Discussion started by: Veera_V
7 Replies

9. Shell Programming and Scripting

Read csv file, convert the data and make one text file in UNIX shell scripting

I have input data looks like this which is a part of a csv file 7,1265,76548,"0102:04" 8,1266,76545,"0112:04" I need to make the output data should look like this and the output data will be part of text file: 7|1265000 |7654899 |A| 8|12660000 |76545999 |B| The logic behind the... (6 Replies)
Discussion started by: RJG
6 Replies

10. Shell Programming and Scripting

Sort data in text file in particular format

I have to sort below output in text file in unix bash 20170308 DA,I,113 20170308 PM,I,123 20170308 DA,U,22 20170308 PM,U,123 20170309 DA,I,11 20170309 PM,I,23 20170309 DA,U,123 20170309 PM,U,233 (8 Replies)
Discussion started by: Adfire
8 Replies
All times are GMT -4. The time now is 12:56 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy