Get one thing from a line and concatenate it with one thing from another line
up vote
4
down vote
favorite
I have the following:
2018-11-10 23:57:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00
Average 9 6 0 84 16.00
2018-11-10 23:58:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00
Average 10 6 0 84 16.00
I need to get the time with the average value of %idle
:
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
text-processing awk sed perl
add a comment |
up vote
4
down vote
favorite
I have the following:
2018-11-10 23:57:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00
Average 9 6 0 84 16.00
2018-11-10 23:58:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00
Average 10 6 0 84 16.00
I need to get the time with the average value of %idle
:
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
text-processing awk sed perl
actually i am getting this file from another server and it is only one file
– ammar
Nov 11 at 13:12
1
This is using this site as a script-writing service.
– Peter Mortensen
Nov 12 at 8:30
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have the following:
2018-11-10 23:57:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00
Average 9 6 0 84 16.00
2018-11-10 23:58:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00
Average 10 6 0 84 16.00
I need to get the time with the average value of %idle
:
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
text-processing awk sed perl
I have the following:
2018-11-10 23:57:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:57:21 %usr %sys %wio %idle physc
23:57:31 10 7 0 83 16.00
23:57:41 9 6 0 85 16.00
23:57:51 9 6 0 85 16.00
23:58:01 9 7 0 84 16.00
23:58:11 10 6 0 84 16.00
Average 9 6 0 84 16.00
2018-11-10 23:58:21 [COMMAND]: sar -u 10 5
AIX host 1 7 11/10/18
System configuration: lcpu=64 mode=Capped
23:58:21 %usr %sys %wio %idle physc
23:58:31 10 8 0 82 15.99
23:58:41 9 6 0 85 16.00
23:58:51 9 6 0 85 16.00
23:59:01 9 6 0 84 16.00
23:59:11 10 6 0 83 16.00
Average 10 6 0 84 16.00
I need to get the time with the average value of %idle
:
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
text-processing awk sed perl
text-processing awk sed perl
edited Nov 12 at 9:07
Peter Mortensen
85758
85758
asked Nov 11 at 13:02
ammar
357
357
actually i am getting this file from another server and it is only one file
– ammar
Nov 11 at 13:12
1
This is using this site as a script-writing service.
– Peter Mortensen
Nov 12 at 8:30
add a comment |
actually i am getting this file from another server and it is only one file
– ammar
Nov 11 at 13:12
1
This is using this site as a script-writing service.
– Peter Mortensen
Nov 12 at 8:30
actually i am getting this file from another server and it is only one file
– ammar
Nov 11 at 13:12
actually i am getting this file from another server and it is only one file
– ammar
Nov 11 at 13:12
1
1
This is using this site as a script-writing service.
– Peter Mortensen
Nov 12 at 8:30
This is using this site as a script-writing service.
– Peter Mortensen
Nov 12 at 8:30
add a comment |
3 Answers
3
active
oldest
votes
up vote
11
down vote
accepted
Going by your input file as-is, a simple awk
command as simple as below should suffice.
awk '/sar/ time=$1" "$2; next /Average/"$5 ' file
add a comment |
up vote
5
down vote
A couple of choices:
awk
$ awk '/COMMAND/printf "%s %s", $1,$2/Average/print "' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84perl
$ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
add a comment |
up vote
2
down vote
This Perl one-liner should do the trick:
perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
if(/^Averages+S+s+S+s+S+s+(S+)/) print "$d'
(I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name
at the beginning or the end, or a pipe will do. The workings are these:
- Go to a line with date and time at the beginning and memorise it.
- Go to a line with
Average
at beginning and once there, print the memorised date and time plus the|
sign and the average taken from the fifth column assuming whitespace column separation. - Point 1. repeats.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
accepted
Going by your input file as-is, a simple awk
command as simple as below should suffice.
awk '/sar/ time=$1" "$2; next /Average/"$5 ' file
add a comment |
up vote
11
down vote
accepted
Going by your input file as-is, a simple awk
command as simple as below should suffice.
awk '/sar/ time=$1" "$2; next /Average/"$5 ' file
add a comment |
up vote
11
down vote
accepted
up vote
11
down vote
accepted
Going by your input file as-is, a simple awk
command as simple as below should suffice.
awk '/sar/ time=$1" "$2; next /Average/"$5 ' file
Going by your input file as-is, a simple awk
command as simple as below should suffice.
awk '/sar/ time=$1" "$2; next /Average/"$5 ' file
answered Nov 11 at 13:16
Inian
3,815824
3,815824
add a comment |
add a comment |
up vote
5
down vote
A couple of choices:
awk
$ awk '/COMMAND/printf "%s %s", $1,$2/Average/print "' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84perl
$ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
add a comment |
up vote
5
down vote
A couple of choices:
awk
$ awk '/COMMAND/printf "%s %s", $1,$2/Average/print "' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84perl
$ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
add a comment |
up vote
5
down vote
up vote
5
down vote
A couple of choices:
awk
$ awk '/COMMAND/printf "%s %s", $1,$2/Average/print "' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84perl
$ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
A couple of choices:
awk
$ awk '/COMMAND/printf "%s %s", $1,$2/Average/print "' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84perl
$ perl -ale '$k="$F[0] $F[1]" if /COMMAND/; print "$k|$F[4]" if /Average/' file
2018-11-10 23:57:21|84
2018-11-10 23:58:21|84
edited Nov 11 at 16:19
answered Nov 11 at 14:48
terdon♦
127k31245422
127k31245422
add a comment |
add a comment |
up vote
2
down vote
This Perl one-liner should do the trick:
perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
if(/^Averages+S+s+S+s+S+s+(S+)/) print "$d'
(I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name
at the beginning or the end, or a pipe will do. The workings are these:
- Go to a line with date and time at the beginning and memorise it.
- Go to a line with
Average
at beginning and once there, print the memorised date and time plus the|
sign and the average taken from the fifth column assuming whitespace column separation. - Point 1. repeats.
add a comment |
up vote
2
down vote
This Perl one-liner should do the trick:
perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
if(/^Averages+S+s+S+s+S+s+(S+)/) print "$d'
(I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name
at the beginning or the end, or a pipe will do. The workings are these:
- Go to a line with date and time at the beginning and memorise it.
- Go to a line with
Average
at beginning and once there, print the memorised date and time plus the|
sign and the average taken from the fifth column assuming whitespace column separation. - Point 1. repeats.
add a comment |
up vote
2
down vote
up vote
2
down vote
This Perl one-liner should do the trick:
perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
if(/^Averages+S+s+S+s+S+s+(S+)/) print "$d'
(I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name
at the beginning or the end, or a pipe will do. The workings are these:
- Go to a line with date and time at the beginning and memorise it.
- Go to a line with
Average
at beginning and once there, print the memorised date and time plus the|
sign and the average taken from the fifth column assuming whitespace column separation. - Point 1. repeats.
This Perl one-liner should do the trick:
perl -lne'$d=$1 if /^(d4-d2-d2s+d2:d2:d2)/;
if(/^Averages+S+s+S+s+S+s+(S+)/) print "$d'
(I made it two lines, so it's more readable.) You need to feed it with input though. The file name at the end, or <file_name
at the beginning or the end, or a pipe will do. The workings are these:
- Go to a line with date and time at the beginning and memorise it.
- Go to a line with
Average
at beginning and once there, print the memorised date and time plus the|
sign and the average taken from the fifth column assuming whitespace column separation. - Point 1. repeats.
edited Nov 11 at 13:23
answered Nov 11 at 13:15
Tomasz
8,85852863
8,85852863
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481082%2fget-one-thing-from-a-line-and-concatenate-it-with-one-thing-from-another-line%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
actually i am getting this file from another server and it is only one file
– ammar
Nov 11 at 13:12
1
This is using this site as a script-writing service.
– Peter Mortensen
Nov 12 at 8:30