Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Creating a two column list of date pairs form a single column list Post 302843704 by jbrandt1979 on Wednesday 14th of August 2013 01:22:00 PM
Old 08-14-2013
Creating a two column list of date pairs form a single column list

Hi all, looking for some help here. I'm what you'd call a dirty programmer. my shell scripts might be ugly, but they (usually) function...

Say I have a single column text file with a list of dates (yyyymmdd) that represent the elevation of a point on that date (I work with land subsidence, so the elevation changes thru time):

Code:
date1
date2
date3
date4
...
date-n

I want to then create another two column text file that contains a list of all possible date combinations, so I can then figure out the change in elevation between two time periods. I need to create this text file for input into another software I use.

Code:
date1  date2
date1  date3
...
date1  date-n
date2  date3
date2  date4
...
date2  date-n
date3  date4
...
date-n-1 date-n

Any ideas?

Thanks all!
JB

Last edited by Scott; 08-14-2013 at 04:16 PM.. Reason: Code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sorting list of files per date column

Hi all, I have a pecular issue in sorting these files (not an ls -lrt) in Solaris environment. All the below files are modified on November 4th, but I want to sort these files as per date (eg: 01May07_1623 = ddmmmyy_hhmm) Nov 4 18:27 SONYELEC00.GI22973.01May07_1623.gpg Nov 4 18:27... (10 Replies)
Discussion started by: shivaastrogun
10 Replies

2. Shell Programming and Scripting

paste each 10 lines of single column to several column

Hi, I need to paste each 10 lines of single column to several columns. Please, can anyone tell me how to write in awk? Input File: 22 34 36 12 17 19 15 11 89 99 56 38 29 (4 Replies)
Discussion started by: nica
4 Replies

3. UNIX for Dummies Questions & Answers

creating a file using the fist column and printing second column

Hello all. I have a problem that I need help solving. I would like to convert the following file: human pool1_12 10e-02 45 67 human pool1_1899 10e-01 45 29 human pool1_1829 10e-01 43 26 horse pool1_343 10e-20 65 191 horse pool1_454 10e-09 44 43... (5 Replies)
Discussion started by: viralnerd
5 Replies

4. UNIX for Advanced & Expert Users

need to get single column form csv file

hi 2 all i need to get single column from one csv file anyone help me ! >cat file.csv name,age x,1 y,2 z,3 Use code tags please, ty. in this "file.csv" file i need only name column can u help me !:b::b: (7 Replies)
Discussion started by: ponmuthu
7 Replies

5. Shell Programming and Scripting

Construct 3 column table from one column list

Hi all! trying my best to parse a public site for information (ie fiscal year and turnover) about corporations. Doing this by having a file with business name and registration number (search key) the file bolag.txt currently looks like this Burgundy 556732-7217 AcademicSearch 556406-9879... (11 Replies)
Discussion started by: martindebruin
11 Replies

6. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

7. UNIX for Dummies Questions & Answers

List several files into one single column

frtgyh (2 Replies)
Discussion started by: lucasvs
2 Replies

8. Shell Programming and Scripting

Converting Single Column into Multiple rows, but with strings to specific tab column

Dear fellows, I need your help. I'm trying to write a script to convert a single column into multiple rows. But it need to recognize the beginning of the string and set it to its specific Column number. Each Line (loop) begins with digit (RANGE). At this moment it's kind of working, but it... (6 Replies)
Discussion started by: AK47
6 Replies

9. Shell Programming and Scripting

Bring values in the second column into single line (comma sep) for uniq value in the first column

I want to bring values in the second column into single line for uniq value in the first column. My input jvm01, Web 2.0 Feature Pack Library jvm01, IBM WebSphere JAX-RS jvm01, Custom01 Shared Library jvm02, Web 2.0 Feature Pack Library jvm02, IBM WebSphere JAX-RS jvm03, Web 2.0 Feature... (10 Replies)
Discussion started by: kchinnam
10 Replies

10. Shell Programming and Scripting

Get maximum per column from CSV file, based on date column

Hello everyone, I am using ksh on Solaris 10 and I'm gathering data in a CSV file that looks like this: 20170628-23:25:01,1,0,0,1,1,1,1,55,55,1 20170628-23:30:01,1,0,0,1,1,1,1,56,56,1 20170628-23:35:00,1,0,0,1,1,2,1,57,57,2 20170628-23:40:00,1,0,0,1,1,1,1,58,58,2... (6 Replies)
Discussion started by: ejianu
6 Replies
Excel::Writer::XLSX::Utility(3pm)			User Contributed Perl Documentation			 Excel::Writer::XLSX::Utility(3pm)

NAME
Utility - Helper functions for Excel::Writer::XLSX. SYNOPSIS
Functions to help with some common tasks when using Excel::Writer::XLSX. These functions mainly relate to dealing with rows and columns in A1 notation and to handling dates and times. use Excel::Writer::XLSX::Utility; # Import everything ($row, $col) = xl_cell_to_rowcol('C2'); # (1, 2) $str = xl_rowcol_to_cell(1, 2); # C2 $str = xl_col_to_name(702); # AAA $str = xl_inc_col('Z1' ); # AA1 $str = xl_dec_col('AA1' ); # Z1 $date = xl_date_list(2002, 1, 1); # 37257 $date = xl_parse_date("11 July 1997"); # 35622 $time = xl_parse_time('3:21:36 PM'); # 0.64 $date = xl_decode_date_EU("13 May 2002"); # 37389 DESCRIPTION
This module provides a set of functions to help with some common tasks encountered when using the Excel::Writer::XLSX module. The two main categories of function are: Row and column functions: these are used to deal with Excel's A1 representation of cells. The functions in this category are: xl_rowcol_to_cell xl_cell_to_rowcol xl_col_to_name xl_range xl_range_formula xl_inc_row xl_dec_row xl_inc_col xl_dec_col Date and Time functions: these are used to convert dates and times to the numeric format used by Excel. The functions in this category are: xl_date_list xl_date_1904 xl_parse_time xl_parse_date xl_parse_date_init xl_decode_date_EU xl_decode_date_US All of these functions are exported by default. However, you can use import lists if you wish to limit the functions that are imported: use Excel::Writer::XLSX::Utility; # Import everything use Excel::Writer::XLSX::Utility qw(xl_date_list); # xl_date_list only use Excel::Writer::XLSX::Utility qw(:rowcol); # Row/col functions use Excel::Writer::XLSX::Utility qw(:dates); # Date functions ROW AND COLUMN FUNCTIONS
Excel::Writer::XLSX supports two forms of notation to designate the position of cells: Row-column notation and A1 notation. Row-column notation uses a zero based index for both row and column while A1 notation uses the standard Excel alphanumeric sequence of column letter and 1-based row. Columns range from A to IV i.e. 0 to 255, rows range from 1 to 16384 in Excel 5 and 65536 in Excel 97. For example: (0, 0) # The top left cell in row-column notation. ('A1') # The top left cell in A1 notation. (1999, 29) # Row-column notation. ('AD2000') # The same cell in A1 notation. Row-column notation is useful if you are referring to cells programmatically: for my $i (0 .. 9) { $worksheet->write($i, 0, 'Hello'); # Cells A1 to A10 } A1 notation is useful for setting up a worksheet manually and for working with formulas: $worksheet->write('H1', 200); $worksheet->write('H2', '=H7+1'); The functions in the following sections can be used for dealing with A1 notation, for example: ($row, $col) = xl_cell_to_rowcol('C2'); # (1, 2) $str = xl_rowcol_to_cell(1, 2); # C2 Cell references in Excel can be either relative or absolute. Absolute references are prefixed by the dollar symbol as shown below: A1 # Column and row are relative $A1 # Column is absolute and row is relative A$1 # Column is relative and row is absolute $A$1 # Column and row are absolute An absolute reference only has an effect if the cell is copied. Refer to the Excel documentation for further details. All of the following functions support absolute references. xl_rowcol_to_cell($row, $col, $row_absolute, $col_absolute) Parameters: $row: Integer $col: Integer $row_absolute: Boolean (1/0) [optional, default is 0] $col_absolute: Boolean (1/0) [optional, default is 0] Returns: A string in A1 cell notation This function converts a zero based row and column cell reference to a A1 style string: $str = xl_rowcol_to_cell(0, 0); # A1 $str = xl_rowcol_to_cell(0, 1); # B1 $str = xl_rowcol_to_cell(1, 0); # A2 The optional parameters $row_absolute and $col_absolute can be used to indicate if the row or column is absolute: $str = xl_rowcol_to_cell(0, 0, 0, 1); # $A1 $str = xl_rowcol_to_cell(0, 0, 1, 0); # A$1 $str = xl_rowcol_to_cell(0, 0, 1, 1); # $A$1 See "ROW AND COLUMN FUNCTIONS" for an explanation of absolute cell references. xl_cell_to_rowcol($string) Parameters: $string String in A1 format Returns: List ($row, $col) This function converts an Excel cell reference in A1 notation to a zero based row and column. The function will also handle Excel's absolute, "$", cell notation. my ($row, $col) = xl_cell_to_rowcol('A1'); # (0, 0) my ($row, $col) = xl_cell_to_rowcol('B1'); # (0, 1) my ($row, $col) = xl_cell_to_rowcol('C2'); # (1, 2) my ($row, $col) = xl_cell_to_rowcol('$C2' ); # (1, 2) my ($row, $col) = xl_cell_to_rowcol('C$2' ); # (1, 2) my ($row, $col) = xl_cell_to_rowcol('$C$2'); # (1, 2) xl_col_to_name($col, $col_absolute) Parameters: $col: Integer $col_absolute: Boolean (1/0) [optional, default is 0] Returns: A column string name. This function converts a zero based column reference to a string: $str = xl_col_to_name(0); # A $str = xl_col_to_name(1); # B $str = xl_col_to_name(702); # AAA The optional parameter $col_absolute can be used to indicate if the column is absolute: $str = xl_col_to_name(0, 0); # A $str = xl_col_to_name(0, 1); # $A $str = xl_col_to_name(1, 1); # $B xl_range($row_1, $row_2, $col_1, $col_2, $row_abs_1, $row_abs_2, $col_abs_1, $col_abs_2) Parameters: $sheetname String $row_1: Integer $row_2: Integer $col_1: Integer $col_2: Integer $row_abs_1: Boolean (1/0) [optional, default is 0] $row_abs_2: Boolean (1/0) [optional, default is 0] $col_abs_1: Boolean (1/0) [optional, default is 0] $col_abs_2: Boolean (1/0) [optional, default is 0] Returns: A worksheet range formula as a string. This function converts zero based row and column cell references to an A1 style range string: my $str = xl_range(0, 9, 0, 0); # A1:A10 my $str = xl_range(1, 8, 2, 2); # C2:C9 my $str = xl_range(0, 3, 0, 4 ); # A1:E4 my $str = xl_range(0, 3, 0, 4, 1 ); # A$1:E4 my $str = xl_range(0, 3, 0, 4, 1, 1); # A$1:E$4 xl_range_formula($sheetname, $row_1, $row_2, $col_1, $col_2) Parameters: $sheetname String $row_1: Integer $row_2: Integer $col_1: Integer $col_2: Integer Returns: A worksheet range formula as a string. This function converts zero based row and column cell references to an A1 style formula string: my $str = xl_range_formula('Sheet1', 0, 9, 0, 0); # =Sheet1!$A$1:$A$10 my $str = xl_range_formula('Sheet2', 6, 65, 1, 1); # =Sheet2!$B$7:$B$66 my $str = xl_range_formula('New data', 1, 8, 2, 2); # ='New data'!$C$2:$C$9 This is useful for setting ranges in Chart objects: $chart->add_series( categories => xl_range_formula('Sheet1', 1, 9, 0, 0), values => xl_range_formula('Sheet1', 1, 9, 1, 1), ); # Which is the same as: $chart->add_series( categories => '=Sheet1!$A$2:$A$10', values => '=Sheet1!$B$2:$B$10', ); xl_inc_row($string) Parameters: $string, a string in A1 format Returns: Incremented string in A1 format This functions takes a cell reference string in A1 notation and increments the row. The function will also handle Excel's absolute, "$", cell notation: my $str = xl_inc_row('A1' ); # A2 my $str = xl_inc_row('B$2' ); # B$3 my $str = xl_inc_row('$C3' ); # $C4 my $str = xl_inc_row('$D$4'); # $D$5 xl_dec_row($string) Parameters: $string, a string in A1 format Returns: Decremented string in A1 format This functions takes a cell reference string in A1 notation and decrements the row. The function will also handle Excel's absolute, "$", cell notation: my $str = xl_dec_row('A2' ); # A1 my $str = xl_dec_row('B$3' ); # B$2 my $str = xl_dec_row('$C4' ); # $C3 my $str = xl_dec_row('$D$5'); # $D$4 xl_inc_col($string) Parameters: $string, a string in A1 format Returns: Incremented string in A1 format This functions takes a cell reference string in A1 notation and increments the column. The function will also handle Excel's absolute, "$", cell notation: my $str = xl_inc_col('A1' ); # B1 my $str = xl_inc_col('Z1' ); # AA1 my $str = xl_inc_col('$B1' ); # $C1 my $str = xl_inc_col('$D$5'); # $E$5 xl_dec_col($string) Parameters: $string, a string in A1 format Returns: Decremented string in A1 format This functions takes a cell reference string in A1 notation and decrements the column. The function will also handle Excel's absolute, "$", cell notation: my $str = xl_dec_col('B1' ); # A1 my $str = xl_dec_col('AA1' ); # Z1 my $str = xl_dec_col('$C1' ); # $B1 my $str = xl_dec_col('$E$5'); # $D$5 TIME AND DATE FUNCTIONS
Dates and times in Excel are represented by real numbers, for example "Jan 1 2001 12:30 AM" is represented by the number 36892.521. The integer part of the number stores the number of days since the epoch and the fractional part stores the percentage of the day in seconds. The epoch can be either 1900 or 1904. Excel for Windows uses 1900 and Excel for Macintosh uses 1904. The epochs are: 1900: 0 January 1900 i.e. 31 December 1899 1904: 1 January 1904 Excel on Windows and the Macintosh will convert automatically between one system and the other. By default Excel::Writer::XLSX uses the 1900 format. To use the 1904 epoch you must use the "set_1904()" workbook method, see the Excel::Writer::XLSX documentation. There are two things to note about the 1900 date format. The first is that the epoch starts on 0 January 1900. The second is that the year 1900 is erroneously but deliberately treated as a leap year. Therefore you must add an extra day to dates after 28 February 1900. The functions in the following section will deal with these issues automatically. The reason for this anomaly is explained at http://support.microsoft.com/support/kb/articles/Q181/3/70.asp Note, a date or time in Excel is like any other number. To display the number as a date you must apply a number format to it: Refer to the "set_num_format()" method in the Excel::Writer::XLSX documentation: $date = xl_date_list(2001, 1, 1, 12, 30); $format->set_num_format('mmm d yyyy hh:mm AM/PM'); $worksheet->write('A1', $date , $format); # Jan 1 2001 12:30 AM To use these functions you must install the "Date::Manip" and "Date::Calc" modules. See REQUIREMENTS and the individual requirements of each functions. See also the DateTime::Format::Excel module,http://search.cpan.org/search?dist=DateTime-Format-Excel which is part of the DateTime project and which deals specifically with converting dates and times to and from Excel's format. xl_date_list($years, $months, $days, $hours, $minutes, $seconds) Parameters: $years: Integer $months: Integer [optional, default is 1] $days: Integer [optional, default is 1] $hours: Integer [optional, default is 0] $minutes: Integer [optional, default is 0] $seconds: Float [optional, default is 0] Returns: A number that represents an Excel date or undef for an invalid date. Requires: Date::Calc This function converts an array of data into a number that represents an Excel date. All of the parameters are optional except for $years. $date1 = xl_date_list(2002, 1, 2); # 2 Jan 2002 $date2 = xl_date_list(2002, 1, 2, 12); # 2 Jan 2002 12:00 pm $date3 = xl_date_list(2002, 1, 2, 12, 30); # 2 Jan 2002 12:30 pm $date4 = xl_date_list(2002, 1, 2, 12, 30, 45); # 2 Jan 2002 12:30:45 pm This function can be used in conjunction with functions that parse date and time strings. In fact it is used in most of the following functions. xl_parse_time($string) Parameters: $string, a textual representation of a time Returns: A number that represents an Excel time or undef for an invalid time. This function converts a time string into a number that represents an Excel time. The following time formats are valid: hh:mm [AM|PM] hh:mm [AM|PM] hh:mm:ss [AM|PM] hh:mm:ss.ss [AM|PM] The meridian, AM or PM, is optional and case insensitive. A 24 hour time is assumed if the meridian is omitted $time1 = xl_parse_time('12:18'); $time2 = xl_parse_time('12:18:14'); $time3 = xl_parse_time('12:18:14 AM'); $time4 = xl_parse_time('1:18:14 AM'); Time in Excel is expressed as a fraction of the day in seconds. Therefore you can calculate an Excel time as follows: $time = ($hours*3600 +$minutes*60 +$seconds)/(24*60*60); xl_parse_date($string) Parameters: $string, a textual representation of a date and time Returns: A number that represents an Excel date or undef for an invalid date. Requires: Date::Manip and Date::Calc This function converts a date and time string into a number that represents an Excel date. The parsing is performed using the "ParseDate()" function of the Date::Manip module. Refer to the Date::Manip documentation for further information about the date and time formats that can be parsed. In order to use this function you will probably have to initialise some Date::Manip variables via the "xl_parse_date_init()" function, see below. xl_parse_date_init("TZ=GMT","DateFormat=non-US"); $date1 = xl_parse_date("11/7/97"); $date2 = xl_parse_date("Friday 11 July 1997"); $date3 = xl_parse_date("10:30 AM Friday 11 July 1997"); $date4 = xl_parse_date("Today"); $date5 = xl_parse_date("Yesterday"); Note, if you parse a string that represents a time but not a date this function will add the current date. If you want the time without the date you can do something like the following: $time = xl_parse_date("10:30 AM"); $time -= int($time); xl_parse_date_init("variable=value", ...) Parameters: A list of Date::Manip variable strings Returns: A list of all the Date::Manip strings Requires: Date::Manip This function is used to initialise variables required by the Date::Manip module. You should call this function before calling "xl_parse_date()". It need only be called once. This function is a thin wrapper for the "Date::Manip::Date_Init()" function. You can use "Date_Init()" directly if you wish. Refer to the Date::Manip documentation for further information. xl_parse_date_init("TZ=MST","DateFormat=US"); $date1 = xl_parse_date("11/7/97"); # November 7th 1997 xl_parse_date_init("TZ=GMT","DateFormat=non-US"); $date1 = xl_parse_date("11/7/97"); # July 11th 1997 xl_decode_date_EU($string) Parameters: $string, a textual representation of a date and time Returns: A number that represents an Excel date or undef for an invalid date. Requires: Date::Calc This function converts a date and time string into a number that represents an Excel date. The date parsing is performed using the "Decode_Date_EU()" function of the Date::Calc module. Refer to the Date::Calc for further information about the date formats that can be parsed. Also note the following from the Date::Calc documentation: "If the year is given as one or two digits only (i.e., if the year is less than 100), it is mapped to the window 1970 -2069 as follows": 0 E<lt>= $year E<lt> 70 ==> $year += 2000; 70 E<lt>= $year E<lt> 100 ==> $year += 1900; The time portion of the string is parsed using the "xl_parse_time()" function described above. Note: the EU in the function name means that a European date format is assumed if it is not clear from the string. See the first example below. $date1 = xl_decode_date_EU("11/7/97"); #11 July 1997 $date2 = xl_decode_date_EU("Sat 12 Sept 1998"); $date3 = xl_decode_date_EU("4:30 AM Sat 12 Sept 1998"); xl_decode_date_US($string) Parameters: $string, a textual representation of a date and time Returns: A number that represents an Excel date or undef for an invalid date. Requires: Date::Calc This function converts a date and time string into a number that represents an Excel date. The date parsing is performed using the "Decode_Date_US()" function of the Date::Calc module. Refer to the Date::Calc for further information about the date formats that can be parsed. Also note the following from the Date::Calc documentation: "If the year is given as one or two digits only (i.e., if the year is less than 100), it is mapped to the window 1970 -2069 as follows": 0 <= $year < 70 ==> $year += 2000; 70 <= $year < 100 ==> $year += 1900; The time portion of the string is parsed using the "xl_parse_time()" function described above. Note: the US in the function name means that an American date format is assumed if it is not clear from the string. See the first example below. $date1 = xl_decode_date_US("11/7/97"); # 7 November 1997 $date2 = xl_decode_date_US("12 Sept Saturday 1998"); $date3 = xl_decode_date_US("4:30 AM 12 Sept Sat 1998"); xl_date_1904($date) Parameters: $date, an Excel date with a 1900 epoch Returns: an Excel date with a 1904 epoch or zero if the $date is before 1904 This function converts an Excel date based on the 1900 epoch into a date based on the 1904 epoch. $date1 = xl_date_list(2002, 1, 13); # 13 Jan 2002, 1900 epoch $date2 = xl_date_1904($date1); # 13 Jan 2002, 1904 epoch See also the "set_1904()" workbook method in the Excel::Writer::XLSX documentation. REQUIREMENTS
The date and time functions require functions from the "Date::Manip" and "Date::Calc" modules. The required functions are "autoused" from these modules so that you do not have to install them unless you wish to use the date and time routines. Therefore it is possible to use the row and column functions without having "Date::Manip" and "Date::Calc" installed. For more information about "autousing" refer to the documentation on the "autouse" pragma. BUGS
When using the autoused functions from "Date::Manip" and "Date::Calc" on Perl 5.6.0 with "-w" you will get a warning like this: "Subroutine xxx redefined ..." The current workaround for this is to put "use warnings;" near the beginning of your program. AUTHOR
John McNamara jmcnamara@cpan.org COPYRIGHT
X MM-MMXII, John McNamara. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. perl v5.10.1 2012-04-02 Excel::Writer::XLSX::Utility(3pm)
All times are GMT -4. The time now is 07:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy