Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Convert text file data into XL file format Post 302999940 by RavinderSingh13 on Friday 30th of June 2017 09:16:16 AM
Old 06-30-2017
Hello scriptor,

Could you please go through the following explanation and let me know if this helps you.
Code:
awk -v Date=$(date +%d) -v Month=$(date +%m) -v Year=$(date +%Y) 'BEGIN{
#####creating variables named Date with current date, Month for current month and Year for current year value.
                                                                        split("Jan,Feb,Mar,Apr,may,Jun,Jul,Aug,Sept,Oct,Nov,Dec", array,",");
#####creating an array named array by split command which has all 12 months names which are separated by comma in it and their index is 1 to 12 digits.
                                                                        MON=array[sprintf("%d",Month)];
#####creating variable named MON which will have current months value in plain English rather than number in it.
                                                                        VAL=Date"-"MON"-"Year
#####creating variable VAL which will have date-month-year format value of complete date value in it.
                                                                        printf("%s%"length(VAL)+1"s %s %s %s %s\n","Date","stat1","stat2","stat3","stat4","stat5");
#####printing the heading here where after 1st column it will take the variable VAL length and print those many spaces between 2nd column and 1st column here.
                                                                       }
                                                                  NR==1{
#####Checking condition if line number is 1 here.
                                                                        print VAL,$0;
#####printing the variable VAL and current line here.
                                                                        next
#####using next keyword of awk here which will skip all further statements.
                                                                       }
                                                                       {
                                                                        printf("%"length(VAL)+1"s%s\n","",$0)
#####printing the value of VAL variable with spaces and then print the current line.
                                                                       }
                                                                 '  Input_file  | mailx -s"test_email"  chumma@chumma.com
####Mentioning Input_file here and sending this command output to mailx command to send email to desired id.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

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
calendar(3erl)						     Erlang Module Definition						    calendar(3erl)

NAME
calendar - Local and universal time, day-of-the-week, date and time conversions DESCRIPTION
This module provides computation of local and universal time, day-of-the-week, and several time conversion functions. Time is local when it is adjusted in accordance with the current time zone and daylight saving. Time is universal when it reflects the time at longitude zero, without any adjustment for daylight saving. Universal Coordinated Time (UTC) time is also called Greenwich Mean Time (GMT). The time functions local_time/0 and universal_time/0 provided in this module both return date and time. The reason for this is that sepa- rate functions for date and time may result in a date/time combination which is displaced by 24 hours. This happens if one of the functions is called before midnight, and the other after midnight. This problem also applies to the Erlang BIFs date/0 and time/0 , and their use is strongly discouraged if a reliable date/time stamp is required. All dates conform to the Gregorian calendar. This calendar was introduced by Pope Gregory XIII in 1582 and was used in all Catholic coun- tries from this year. Protestant parts of Germany and the Netherlands adopted it in 1698, England followed in 1752, and Russia in 1918 (the October revolution of 1917 took place in November according to the Gregorian calendar). The Gregorian calendar in this module is extended back to year 0. For a given date, the gregorian days is the number of days up to and including the date specified. Similarly, the gregorian seconds for a given date and time, is the the number of seconds up to and including the specified date and time. For computing differences between epochs in time, use the functions counting gregorian days or seconds. If epochs are given as local time, they must be converted to universal time, in order to get the correct value of the elapsed time between epochs. Use of the function time_difference/2 is discouraged. There exists different definitions for the week of the year. The calendar module contains a week of the year implementation which conforms to the ISO 8601 standard. Since the week number for a given date can fall on the previous, the current or on the next year it is important to provide the information which year is it together with the week number. The function iso_week_number/0 and iso_week_number/1 returns a tuple of the year and the week number. DATA TYPES
date() = {Year, Month, Day} Year = int() Month = 1..12 Day = 1..31 Year cannot be abbreviated. Example: 93 denotes year 93, not 1993. Valid range depends on the underlying OS. The date tuple must denote a valid date. time() = {Hour, Minute, Second} Hour = 0..23 Minute = Second = 0..59 EXPORTS
date_to_gregorian_days(Date) -> Days date_to_gregorian_days(Year, Month, Day) -> Days Types Date = date() Days = int() This function computes the number of gregorian days starting with year 0 and ending at the given date. datetime_to_gregorian_seconds({Date, Time}) -> Seconds Types Date = date() Time = time() Seconds = int() This function computes the number of gregorian seconds starting with year 0 and ending at the given date and time. day_of_the_week(Date) -> DayNumber day_of_the_week(Year, Month, Day) -> DayNumber Types Date = date() DayNumber = 1..7 This function computes the day of the week given Year , Month and Day . The return value denotes the day of the week as 1 : Monday, 2 : Tuesday, and so on. gregorian_days_to_date(Days) -> Date Types Days = int() Date = date() This function computes the date given the number of gregorian days. gregorian_seconds_to_datetime(Seconds) -> {Date, Time} Types Seconds = int() Date = date() Time = time() This function computes the date and time from the given number of gregorian seconds. is_leap_year(Year) -> bool() This function checks if a year is a leap year. iso_week_number() -> IsoWeekNumber Types IsoWeekNumber = {int(), int()} This function returns the tuple {Year, WeekNum} representing the iso week number for the actual date. For determining the actual date, the function local_time/0 is used. iso_week_number(Date) -> IsoWeekNumber Types Date = date() IsoWeekNumber = {int(), int()} This function returns the tuple {Year, WeekNum} representing the iso week number for the given date. last_day_of_the_month(Year, Month) -> int() This function computes the number of days in a month. local_time() -> {Date, Time} Types Date = date() Time = time() This function returns the local time reported by the underlying operating system. local_time_to_universal_time({Date1, Time1}) -> {Date2, Time2} This function converts from local time to Universal Coordinated Time (UTC). Date1 must refer to a local date after Jan 1, 1970. Warning: This function is deprecated. Use local_time_to_universal_time_dst/1 instead, as it gives a more correct and complete result. Especially for the period that does not exist since it gets skipped during the switch to daylight saving time, this function still returns a result. local_time_to_universal_time_dst({Date1, Time1}) -> [{Date, Time}] Types Date1 = Date = date() Time1 = Time = time() This function converts from local time to Universal Coordinated Time (UTC). Date1 must refer to a local date after Jan 1, 1970. The return value is a list of 0, 1 or 2 possible UTC times: [] : For a local {Date1, Time1} during the period that is skipped when switching to daylight saving time, there is no corresponding UTC since the local time is illegal - it has never happened. [DstDateTimeUTC, DateTimeUTC] : For a local {Date1, Time1} during the period that is repeated when switching from daylight saving time, there are two corre- sponding UTCs. One for the first instance of the period when daylight saving time is still active, and one for the second instance. [DateTimeUTC] : For all other local times there is only one corresponding UTC. now_to_local_time(Now) -> {Date, Time} Types Now -- see erlang:now/0 Date = date() Time = time() This function returns local date and time converted from the return value from erlang:now() . now_to_universal_time(Now) -> {Date, Time} now_to_datetime(Now) -> {Date, Time} Types Now -- see erlang:now/0 Date = date() Time = time() This function returns Universal Coordinated Time (UTC) converted from the return value from erlang:now() . seconds_to_daystime(Seconds) -> {Days, Time} Types Seconds = Days = int() Time = time() This function transforms a given number of seconds into days, hours, minutes, and seconds. The Time part is always non-negative, but Days is negative if the argument Seconds is. seconds_to_time(Seconds) -> Time Types Seconds = int() < 86400 Time = time() This function computes the time from the given number of seconds. Seconds must be less than the number of seconds per day(86400). time_difference(T1, T2) -> {Days, Time} This function returns the difference between two {Date, Time} tuples. T2 should refer to an epoch later than T1 . Warning: This function is obsolete. Use the conversion functions for gregorian days and seconds instead. time_to_seconds(Time) -> Seconds Types Time = time() Seconds = int() This function computes the number of seconds since midnight up to the specified time. universal_time() -> {Date, Time} Types Date = date() Time = time() This function returns the Universal Coordinated Time (UTC) reported by the underlying operating system. Local time is returned if universal time is not available. universal_time_to_local_time({Date1, Time1}) -> {Date2, Time2} Types Date1 = Date2 = date() Time1 = Time2 = time() This function converts from Universal Coordinated Time (UTC) to local time. Date1 must refer to a date after Jan 1, 1970. valid_date(Date) -> bool() valid_date(Year, Month, Day) -> bool() Types Date = date() This function checks if a date is a valid. LEAP YEARS
The notion that every fourth year is a leap year is not completely true. By the Gregorian rule, a year Y is a leap year if either of the following rules is valid: * Y is divisible by 4, but not by 100; or * Y is divisible by 400. Accordingly, 1996 is a leap year, 1900 is not, but 2000 is. DATE AND TIME SOURCE
Local time is obtained from the Erlang BIF localtime/0 . Universal time is computed from the BIF universaltime/0 . The following facts apply: * there are 86400 seconds in a day * there are 365 days in an ordinary year * there are 366 days in a leap year * there are 1461 days in a 4 year period * there are 36524 days in a 100 year period * there are 146097 days in a 400 year period * there are 719528 days between Jan 1, 0 and Jan 1, 1970. Ericsson AB stdlib 1.17.3 calendar(3erl)
All times are GMT -4. The time now is 05:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy