Re: data manipulation question



KKde wrote:

On Aug 3, 10:02 pm, "John W. Krahn" <some...@xxxxxxxxxxx> wrote:

$ echo "01:00:00 c1t0d0 0.10 0.66 8 111 0.08 0.29
c1t0d1 0.04 0.50 3 61 0.00 0.14
02:00:00 c1t0d0 0.07 2.83 7 126 0.04 0.15
c1t0d1 0.02 0.50 2 48 0.00 0.09
03:00:00 c1t0d0 0.04 0.53 6 86 0.00 0.09
c1t0d1 0.03 0.50 2 47 0.00 0.13
04:00:00 c1t0d0 0.05 0.52 6 85 0.00 0.09
c1t0d1 0.02 0.50 2 47 0.00 0.10" |
perl -pe'/^([\d:]+)/and$a=$1;s/^\s{@{[length$a]}}/$a/'
01:00:00 c1t0d0 0.10 0.66 8 111 0.08 0.29
01:00:00 c1t0d1 0.04 0.50 3 61 0.00 0.14
02:00:00 c1t0d0 0.07 2.83 7 126 0.04 0.15
02:00:00 c1t0d1 0.02 0.50 2 48 0.00 0.09
03:00:00 c1t0d0 0.04 0.53 6 86 0.00 0.09
03:00:00 c1t0d1 0.03 0.50 2 47 0.00 0.13
04:00:00 c1t0d0 0.05 0.52 6 85 0.00 0.09
04:00:00 c1t0d1 0.02 0.50 2 47 0.00 0.10

Hi John,

I couldn't understand this expression s/^\s{@{[length$a]}}/$a/' Can
you please explain in detail what this part is doing {@{[length$a]}}

That could also be written as:

$len = length $a; s/^\s{$len}/$a/

Or since the string being replaced is always 8 bytes long:

s/^\s{8}/$a/


In other words, match that there are the same number of whitespace characters at the start of the string as the length of the time string and if there are replace the whitespace characters with the time string.



John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
.



Relevant Pages

  • RE: Newbie question about file input
    ... Return a list of the words of the string s. ... whitespace characters. ... optional third argument maxsplit defaults to 0. ... > Aaron Deskins ...
    (comp.lang.python)
  • Re: converting dates to intervals
    ... I don't want to consolidate to the nearest 5-min ... Put back into string w/ datestr ... Use datenumon the time string then pass that to datevec() ...
    (comp.soft-sys.matlab)
  • Re: Testing strings for characters?
    ... > I'm trying to test strings for whitespace characters. ... > function isspace() that handles this. ... > under VB6? ... Function ContainsWhiteSpace(StrIn As String) As Boolean ...
    (microsoft.public.vb.general.discussion)
  • Re: Newbie question about file input
    ... > import string ... A line without anything but whitespace characters "splits" to an empty ... a blank line is not really empty but contains a newline ... readline() returns an empty string. ...
    (comp.lang.python)
  • Help with splitting
    ... save the whitespace characters rather than discarding them. ... I was certain that there was a way to do this using the standard string ... but I just spent some time poring over the documentation ... but I also spent some time there without luck. ...
    (comp.lang.python)