Help with String Extraction - Variation

Help with String Extraction - Variation

am 26.09.2007 12:29:23 von vishal78

Hello All,

My requirement is:

This is my file status.txt

server0 up 6 days 4:42 load average: 0.01 0.02 0.03
server1 up 8 days 22:54 load average: 0.01 0.06 0.05
server2 up 4 days 2:03 load average: 0.02 0.01 0.01
server3 up 7 days 22:46 load average: 0.01 0.03 0.04

i want to extract parse this file such that the output looks like
this:

load average: 0.01 0.02 0.03
load average: 0.01 0.06 0.05
load average: 0.02 0.01 0.01
load average: 0.01 0.03 0.04

How do i use sed/awk combination to achieve the above output.

Thanks in advance.

Regards,
Vishal Sharma

Re: Help with String Extraction - Variation

am 26.09.2007 12:40:55 von cfajohnson

On 2007-09-26, Vishal Sharma wrote:
> Hello All,
>
> My requirement is:
>
> This is my file status.txt
>
> server0 up 6 days 4:42 load average: 0.01 0.02 0.03
> server1 up 8 days 22:54 load average: 0.01 0.06 0.05
> server2 up 4 days 2:03 load average: 0.02 0.01 0.01
> server3 up 7 days 22:46 load average: 0.01 0.03 0.04
>
> i want to extract parse this file such that the output looks like
> this:
>
> load average: 0.01 0.02 0.03
> load average: 0.01 0.06 0.05
> load average: 0.02 0.01 0.01
> load average: 0.01 0.03 0.04
>
> How do i use sed/awk combination to achieve the above output.

No combination needed, just awk:

awk '{print $6,$7,$8,$9,$10}' FILE

Or even cut:

cut -c32- FILE

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Re: Help with String Extraction - Variation

am 26.09.2007 12:53:12 von vishal78

On Sep 26, 6:40 pm, "Chris F.A. Johnson" wrote:
> On 2007-09-26, Vishal Sharma wrote:
>
>
>
> > Hello All,
>
> > My requirement is:
>
> > This is my file status.txt
>
> > server0 up 6 days 4:42 load average: 0.01 0.02 0.03
> > server1 up 8 days 22:54 load average: 0.01 0.06 0.05
> > server2 up 4 days 2:03 load average: 0.02 0.01 0.01
> > server3 up 7 days 22:46 load average: 0.01 0.03 0.04
>
> > i want to extract parse this file such that the output looks like
> > this:
>
> > load average: 0.01 0.02 0.03
> > load average: 0.01 0.06 0.05
> > load average: 0.02 0.01 0.01
> > load average: 0.01 0.03 0.04
>
> > How do i use sed/awk combination to achieve the above output.
>
> No combination needed, just awk:
>
> awk '{print $6,$7,$8,$9,$10}' FILE
>
> Or even cut:
>
> cut -c32- FILE
>
> --
> Chris F.A. Johnson, author
> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
> ===== My code in this post, if any, assumes the POSIX locale
> ===== and is released under the GNU General Public Licence

Why i need to only extract from the "load average" string, is because
everytime the output of command uptime might vary. sometimes the time
is shown like this

server0 up 6 days 42 mins load average: 0.01 0.02 0.03

so in such a case your suggestion might not work. So the easiest would
be to search for the word "load" and extract everything after that.

Pls provide me some solution.

Thanks,

Re: Help with String Extraction - Variation

am 26.09.2007 13:55:22 von Icarus Sparry

On Wed, 26 Sep 2007 10:53:12 +0000, Vishal Sharma wrote:

[snip]

> Why i need to only extract from the "load average" string, is because
> everytime the output of command uptime might vary. sometimes the time is
> shown like this
>
> server0 up 6 days 42 mins load average: 0.01 0.02 0.03
>
> so in such a case your suggestion might not work. So the easiest would
> be to search for the word "load" and extract everything after that.
>
> Pls provide me some solution.
>
> Thanks,

So you have a clear requirement, just write it....

sed 's/^.*load/load/'

or in english, the sed "program s/^.*load/load, protected by "'"
characters so the shell leaves it alone
s substitue
/ use / as the pattern delimiter
^ start of line
.. any character
* repeated any number of times, including zero
load followed by "l", "o", "a", and "d" in that order
/ end of first pattern, start of second pattern
load the characters "l", "o", "a", and "d"
/ end of second pattern