<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: text manipulation challenge in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060278#M94115</link>
    <description>Thx all</description>
    <pubDate>Sat, 28 Jul 2007 11:47:02 GMT</pubDate>
    <dc:creator>Duncan Edmonstone</dc:creator>
    <dc:date>2007-07-28T11:47:02Z</dc:date>
    <item>
      <title>text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060268#M94105</link>
      <description>Hi all,&lt;BR /&gt;&lt;BR /&gt;TRying to figure out a quick and easy solution to the following problem...&lt;BR /&gt;&lt;BR /&gt;I have two sets of measureware data from 2 systems in different timezones (GMT0BST and EST5DST). Both sets of data looks like this:&lt;BR /&gt;&lt;BR /&gt;&lt;DATE&gt; &lt;TIME&gt; &lt;METRIC&gt;&lt;BR /&gt;&lt;BR /&gt;e.g. UK data:&lt;BR /&gt;&lt;BR /&gt;07/27/07 09:00 27.2&lt;BR /&gt;07/27/07 09:05 22.4&lt;BR /&gt;&lt;BR /&gt;etc.&lt;BR /&gt;&lt;BR /&gt;US data:&lt;BR /&gt;&lt;BR /&gt;07/27/07 04:00 16.5&lt;BR /&gt;07/27/07 04:05 18.1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now I need to take the two sets and combine the results together, but *taking into account the timezone differences* - so I need to add 5 hours onto the ESTDST time to match up with GMTBST and then match up the data with the data from the same time on the other system. I end up with data looking like this:&lt;BR /&gt;&lt;BR /&gt;&lt;DATE&gt; &lt;TIME&gt; &lt;METRIC1&gt; &lt;METRIC2&gt;&lt;BR /&gt;&lt;BR /&gt;e.g.&lt;BR /&gt;&lt;BR /&gt;07/27/07 09:00 27.2 16.5&lt;BR /&gt;07/27/07 09:05 22.4 18.1&lt;BR /&gt;&lt;BR /&gt;unfortunately there may also be inconsistent gaps in the data (where systems have been rebooted)&lt;BR /&gt;&lt;BR /&gt;Any ideas on how to do a quick timezone conversion and then match up each data item?&lt;BR /&gt;&lt;BR /&gt;Thx&lt;BR /&gt;&lt;BR /&gt;Duncan&lt;/METRIC2&gt;&lt;/METRIC1&gt;&lt;/TIME&gt;&lt;/DATE&gt;&lt;/METRIC&gt;&lt;/TIME&gt;&lt;/DATE&gt;</description>
      <pubDate>Fri, 27 Jul 2007 09:19:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060268#M94105</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2007-07-27T09:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060269#M94106</link>
      <description>Not sure if this can be done but how about getting the measureware output from both systems relative to a timezone? For example you could use UTC as the baseline for both systems and then have measureware output the data you want. This atleast will take care of the date and time conversion. Afterwards the task should be a simple shell or awk script.</description>
      <pubDate>Fri, 27 Jul 2007 09:54:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060269#M94106</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-07-27T09:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060270#M94107</link>
      <description>Sandman,&lt;BR /&gt;&lt;BR /&gt;I knew I should have mentioned this in my original post:&lt;BR /&gt;&lt;BR /&gt;I don't have access to the original systems!&lt;BR /&gt;&lt;BR /&gt;That was my first idea, but it took an age to get the data in the first place...&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Duncan&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Jul 2007 09:56:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060270#M94107</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2007-07-27T09:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060271#M94108</link>
      <description>Hi Duncan,&lt;BR /&gt;&lt;BR /&gt;Interesting little problem - and a sneaky awk solution;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt; &lt;BR /&gt;awk -F"[ :]" '{printf "%s %.2d:%s %s\n",$1,$2+5,$3,$4}' us.txt &amp;gt; us.tmp&lt;BR /&gt; &lt;BR /&gt;for LINE in `cat uk.txt | sed -e s/" "/_/g`&lt;BR /&gt;do&lt;BR /&gt;DATE_TIME=`echo $LINE | awk -F_ '{print $1" "$2}'`&lt;BR /&gt;METRIC=`echo $LINE | awk -F_ '{print $3}'`&lt;BR /&gt;METRIC2=`grep "$DATE_TIME" us.tmp | cut -c16-19`&lt;BR /&gt;echo "$DATE_TIME $METRIC $METRIC2"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;It seems to work with your sample data - and should cope with missing bits to some extent (if the US part is missing, you'll just end up with the date/time and uk metric, if the UK part is missing, you get nothing)&lt;BR /&gt;&lt;BR /&gt;I know the replacement of a space with an _ for the loop isn't the best way of doing it, but couldn't seem to get it to work setting the IFS variable.&lt;BR /&gt;&lt;BR /&gt;Chris</description>
      <pubDate>Fri, 27 Jul 2007 10:34:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060271#M94108</guid>
      <dc:creator>Chris Wilshaw</dc:creator>
      <dc:date>2007-07-27T10:34:31Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060272#M94109</link>
      <description>Forgot to mention, I'd put the data into uk.txt and us.txt files for convenience, and although it's hard to see, there's a space before the : in the awk field separator brackets.&lt;BR /&gt;&lt;BR /&gt;And just realised another problem - silly me, I've added 5 to whatever figure you have in the time field, so you could end up with 28:00 hours.&lt;BR /&gt;&lt;BR /&gt;Oh well, it was worth a try.</description>
      <pubDate>Fri, 27 Jul 2007 10:39:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060272#M94109</guid>
      <dc:creator>Chris Wilshaw</dc:creator>
      <dc:date>2007-07-27T10:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060273#M94110</link>
      <description>&lt;!--!*#--&gt;Hi Duncan:&lt;BR /&gt;&lt;BR /&gt;Perl will handle all of this:&lt;BR /&gt;&lt;BR /&gt;# cat .compareit&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use POSIX qw(strftime);&lt;BR /&gt;use Time::Local;&lt;BR /&gt;&lt;BR /&gt;my $localdata = shift or die "LocalData expected\n";&lt;BR /&gt;my $gmtdata   = shift or die "GMT  Data expected\n";&lt;BR /&gt;&lt;BR /&gt;my ( $mon, $mday, $year, $hours, $min, $metric );&lt;BR /&gt;my ( $time, $gmt );&lt;BR /&gt;my %results;&lt;BR /&gt;&lt;BR /&gt;open( LD, "&amp;lt;", $localdata ) or die "Can't open '$localdata': $!\n";&lt;BR /&gt;while (&lt;LD&gt;) {&lt;BR /&gt;    ( $mon, $mday, $year, $hours, $min, $metric )&lt;BR /&gt;        = m{(\d\d)/(\d\d)/(\d\d)\s+(\d\d):(\d\d)\s+(.+)};&lt;BR /&gt;    $time = timelocal( 0, $min, $hours, $mday, $mon - 1, $year );&lt;BR /&gt;    $gmt = strftime "%m/%d/%y %H:%M", gmtime($time);&lt;BR /&gt;    $results{$gmt} = $metric;&lt;BR /&gt;}&lt;BR /&gt;close LD;&lt;BR /&gt;open( LD, "&amp;lt;", $localdata ) or die "Can't open '$localdata': $!\n";&lt;BR /&gt;while (&lt;LD&gt;) {&lt;BR /&gt;    ( $mon, $mday, $year, $hours, $min, $metric )&lt;BR /&gt;        = m{(\d\d)/(\d\d)/(\d\d)\s+(\d\d):(\d\d)\s+(.+)};&lt;BR /&gt;    $time = timelocal( 0, $min, $hours, $mday, $mon - 1, $year );&lt;BR /&gt;    $gmt = strftime "%m/%d/%y %H:%M", gmtime($time);&lt;BR /&gt;    $results{$gmt} = $metric;&lt;BR /&gt;}&lt;BR /&gt;close LD;&lt;BR /&gt;&lt;BR /&gt;open( GD, "&amp;lt;", $gmtdata ) or die "Can't open '$gmtdata': $!\n";&lt;BR /&gt;while (&lt;GD&gt;) {&lt;BR /&gt;    ( $mon, $mday, $year, $hours, $min, $metric )&lt;BR /&gt;        = m{(\d\d)/(\d\d)/(\d\d)\s+(\d\d):(\d\d)\s+(.+)};&lt;BR /&gt;    $time = timegm( 0, $min, $hours, $mday, $mon - 1, $year );&lt;BR /&gt;    $gmt = strftime "%m/%d/%y %H:%M", gmtime($time);&lt;BR /&gt;    $results{$gmt} .= " $metric";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;for my $key ( sort keys %results ) {&lt;BR /&gt;    print join " ", $key, $results{$key}, "\n";&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...run as passing your two files:&lt;BR /&gt;&lt;BR /&gt;# ./compareit localtimedata gmttimedata&lt;BR /&gt;&lt;BR /&gt;I rather quickly cobbled this together and it could be make a bit cleaner, but it should server your purpose.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/GD&gt;&lt;/LD&gt;&lt;/LD&gt;</description>
      <pubDate>Fri, 27 Jul 2007 10:40:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060273#M94110</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-07-27T10:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060274#M94111</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;Thx - that did the trick - one quick question to get that extra point though - is the final output in GMT or EST? (My per is sooo rusty now, I can hardly even read the syntax any more!)&lt;BR /&gt;&lt;BR /&gt;Duncan</description>
      <pubDate>Fri, 27 Jul 2007 10:55:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060274#M94111</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2007-07-27T10:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060275#M94112</link>
      <description>Hi (again) Duncan:&lt;BR /&gt;&lt;BR /&gt;Yes, I should have mentioned that the final output is in GMT (UTC) units.  I felt that that was the most appropriate units.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 27 Jul 2007 10:58:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060275#M94112</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-07-27T10:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060276#M94113</link>
      <description>You could use the source code pasted below to convert the US ESTDST date/time stamps into UTC; then concatenate the GMT &amp;amp; UTC files using the awk script as:&lt;BR /&gt;&lt;BR /&gt;-- compile the source code pasted below&lt;BR /&gt;cc mysrcode.c -o mysrcode&lt;BR /&gt;&lt;BR /&gt;-- generate UTC date/time stamps from the EST date/time stamp file&lt;BR /&gt;mysrcode &lt;US_FILE&gt;UTC_file&lt;BR /&gt;&lt;BR /&gt;-- run awk script to concatenate the files&lt;BR /&gt;&lt;BR /&gt;awk '{&lt;BR /&gt;if (x[$1" "$2])&lt;BR /&gt;x[$1" "$2]=x[$1" "$2]" "$NF&lt;BR /&gt;else&lt;BR /&gt;x[$1" "$2]=$0&lt;BR /&gt;}END{for(i in x) print x[i]}' GMT_file UTC_file&lt;BR /&gt;&lt;BR /&gt;====================================================================&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;TIME.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char **argv)&lt;BR /&gt;{&lt;BR /&gt;int mo, day, yr, hr, min;&lt;BR /&gt;time_t tloc, *ptloc = &amp;amp;tloc;&lt;BR /&gt;char buf[BUFSIZ]; struct tm *tmptr; float var;&lt;BR /&gt;&lt;BR /&gt;while (gets(buf) != NULL)&lt;BR /&gt;{&lt;BR /&gt;sscanf(buf,"%2d%*c%2d%*c%2d%2d%*c%2d%f",&amp;amp;mo,&amp;amp;day,&amp;amp;yr,&amp;amp;hr,&amp;amp;min,&amp;amp;var);&lt;BR /&gt;time(ptloc); tmptr = gmtime(ptloc);&lt;BR /&gt;tmptr-&amp;gt;tm_year = yr; tmptr-&amp;gt;tm_mon = mo;&lt;BR /&gt;tmptr-&amp;gt;tm_mday = day; tmptr-&amp;gt;tm_hour = hr + 5;&lt;BR /&gt;tmptr-&amp;gt;tm_min = min; mktime(tmptr);&lt;BR /&gt;printf("%.2d/%.2d/%.2d %.2d:%.2d %.1f\n",tmptr-&amp;gt;tm_mon,tmptr-&amp;gt;tm_mday,&lt;BR /&gt;tmptr-&amp;gt;tm_year,tmptr-&amp;gt;tm_hour,tmptr-&amp;gt;tm_min, var);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/TIME.H&gt;&lt;/STDIO.H&gt;&lt;/US_FILE&gt;</description>
      <pubDate>Fri, 27 Jul 2007 13:45:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060276#M94113</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2007-07-27T13:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060277#M94114</link>
      <description>&lt;!--!*#--&gt;Hi (again) Duncan:&lt;BR /&gt;&lt;BR /&gt;My post inadvertantly pasted a block of code twice (although it did work).&lt;BR /&gt;&lt;BR /&gt;Here's a faster version that supports dates and times without leading zeros.  Thus:&lt;BR /&gt;&lt;BR /&gt;7/7/07 7:01 27.2&lt;BR /&gt;&lt;BR /&gt;...is equivalent to:&lt;BR /&gt;&lt;BR /&gt;07/07/07 07:01 27.2&lt;BR /&gt;&lt;BR /&gt;Moreover, the output clearly shows where a sample on one system or the other is missing.  You might see:&lt;BR /&gt;&lt;BR /&gt;07/27/07 14:59  - GMT_metric&lt;BR /&gt;07/27/07 15:00 localmetric GMT_metric&lt;BR /&gt;07/27/07 15:01 localmetric&lt;BR /&gt;&lt;BR /&gt;# cat .compareit&lt;BR /&gt;#!/usr/bin/perl &lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use POSIX qw(strftime);&lt;BR /&gt;use Time::Local;&lt;BR /&gt;&lt;BR /&gt;my $localdata = shift or die "LocalData expected\n";&lt;BR /&gt;my $gmtdata   = shift or die "GMT  Data expected\n";&lt;BR /&gt;&lt;BR /&gt;my ( $mon, $mday, $year, $hours, $min, $metric );&lt;BR /&gt;my ( $time, $gmt );&lt;BR /&gt;my %results;&lt;BR /&gt;&lt;BR /&gt;open( LD, "&amp;lt;", $localdata ) or die "Can't open '$localdata': $!\n";&lt;BR /&gt;while (&lt;LD&gt;) {&lt;BR /&gt;    ( $mon, $mday, $year, $hours, $min, $metric )&lt;BR /&gt;        = m{(\d\d?)/(\d\d?)/(\d\d)\s+(\d\d):(\d\d)\s+(.+)};&lt;BR /&gt;    $time = timelocal( 0, $min, $hours, $mday, $mon - 1, $year );&lt;BR /&gt;    $gmt = strftime "%m/%d/%y %H:%M", gmtime($time);&lt;BR /&gt;    $results{$gmt} = $metric;&lt;BR /&gt;}&lt;BR /&gt;close LD;&lt;BR /&gt;&lt;BR /&gt;open( GD, "&amp;lt;", $gmtdata ) or die "Can't open '$gmtdata': $!\n";&lt;BR /&gt;while (&lt;GD&gt;) {&lt;BR /&gt;    ( $mon, $mday, $year, $hours, $min, $metric )&lt;BR /&gt;        = m{(\d\d?)/(\d\d?)/(\d\d)\s+(\d\d?):(\d\d)\s+(.+)};&lt;BR /&gt;    $gmt = sprintf "%02d/%02d/%02d %02d:%02d", $mon, $mday, $year, $hours,&lt;BR /&gt;        $min;&lt;BR /&gt;    if ( exists $results{$gmt} ) {&lt;BR /&gt;        $results{$gmt} .= " " . $metric;&lt;BR /&gt;    }&lt;BR /&gt;    else {&lt;BR /&gt;        $results{$gmt} = " - " . $metric;&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;close GD;&lt;BR /&gt;&lt;BR /&gt;for my $key ( sort keys %results ) {&lt;BR /&gt;    printf "%s %-s\n", $key, $results{$key};&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...as before, run as:&lt;BR /&gt;&lt;BR /&gt;# .compareit local_time_data gm_time_data&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;/GD&gt;&lt;/LD&gt;</description>
      <pubDate>Fri, 27 Jul 2007 14:52:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060277#M94114</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-07-27T14:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: text manipulation challenge</title>
      <link>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060278#M94115</link>
      <description>Thx all</description>
      <pubDate>Sat, 28 Jul 2007 11:47:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/text-manipulation-challenge/m-p/5060278#M94115</guid>
      <dc:creator>Duncan Edmonstone</dc:creator>
      <dc:date>2007-07-28T11:47:02Z</dc:date>
    </item>
  </channel>
</rss>

