Re: data manipulation question
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Thu, 06 Aug 2009 03:37:04 -0700
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
.
- References:
- data manipulation question
- From: banzai
- Re: data manipulation question
- From: John W. Krahn
- Re: data manipulation question
- From: KKde
- data manipulation question
- Prev by Date: Re: Odd behavior with IFS and $@
- Next by Date: Re: smarter history recall in bash
- Previous by thread: Re: data manipulation question
- Next by thread: Re: data manipulation question
- Index(es):
Relevant Pages
|