INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

how to concate line in four variables or array

how to concate line in four variables or array

how to concate line in four variables or array

(OP)
Hello all,

I need your help to transform an output of Iostat file
hereafter the bloc
hdisk0 transfer : %tm_act bps tps bread bwrtn
0,2 18,8K 4,6 0,0 18,8K
lect. : rps moyserv minserv maxserv délais échecs
0,0 0,0 0,0 [center] 0,0 0 0
écriture : wps moyserv minserv maxserv délais échecs
4,6 0,2 0,1 21,9 0 0
File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
0,0 0,0 0,0 0,0 0,0 0,0
cd0 transfer : %tm_act bps tps bread bwrtn
0,0 0,0 0,0 0,0 0,0
hdisk1 transfer : %tm_act bps tps bread bwrtn
2,0 250,7K 32,8 59,0K 191,7K
lect. : rps moyserv minserv maxserv délais échecs
9,6 2,1 0,2 8,0 0 0
écriture : wps moyserv minserv maxserv délais échecs
23,2 0,2 0,1 20,9 0 0
File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
0,0 0,0 0,0 0,0 0,0 0,0

i want to have a new file with this form

line 1 + line 3 + line 5 + line 7
line 2 + line 4 + line 6 + line 8
line 11 + line 13 + line 15 + line 17
line 12 + line 14 + line 16 + line 18

i tried with awk using for, if and concacte variable, but "\n" made issue, i think.

think a lot.

RE: how to concate line in four variables or array

(OP)
Hi PHV,
I have to analyse iostat output, but for each disk (hdisk0 and hdisk1) i have 8 lines.
the first, the third, the fifht and the seventh is the title of each colomns of stats.
I want to have just one line and the same for stats values (second, fourth, sixth and eighth)
i tried with some if to concate line in a variable with this : hisdk0=hdisk0 $0. But when i print the value, i i have the lastest $0.
I think that the 'line return' is the trouble.
hereafter the output i would like to have:
hdisk0;transfer;:;%tm_act;bps;tps;bread;bwrtn;lect.;:;rps;moyserv;minserv;maxserv;délais;échecs;écriture;:;wps;moyserv;minserv;maxserv;délais;échecs;File;d'attente;:;avgtime;mintime;maxtime;avgwqsz;avgsqsz;sqfull;
;0,6;28,7K;7,0;0,0;28,7K;0,0;0,0;0,0;0,0;0;0;7,0;1,3;0,1;21,9;0;0;0,0;0,0;0,0;0,0;0,0;0,0
hdisk1;transfer;:;%tm_act;bps;tps;bread;bwrtn;lect.;:;rps;moyserv;minserv;maxserv;délais;échecs;écriture;:;wps;moyserv;minserv;maxserv;délais;échecs;File;d'attente;:;avgtime;mintime;maxtime;avgwqsz;avgsqsz;sqfull
;1,8;257,2K;30,4;27,9K;229,4K;5,8;1,5;0,2;7,2;0;0;24,6;0,5;0,1;20,9;0;0;0,0;0,0;0,0;0,0;0,0;0,0

Is it more clear for you?
thank in advance.
Pascal

RE: how to concate line in four variables or array

(OP)

I made a mistask when i wrote the post.
in my commande line, i have this, and it don't work as i dsicribed in my last post.
Perhaps the solution is in parsing each field in a line to add in the good variable?

RE: how to concate line in four variables or array

(OP)

my command line:
cat test.txt |awk '
/hdisk0/ {
hdisk0=hdisk0 $0;getline
val0=val0 $0;getline
hdisk0=hdisk0 $0;getline
val0=val0 $0;getline
hdisk0=hdisk0 $0;getline
val0=val0 $0;getline
hdisk0=hdisk0 $0;getline
val0=val0 $0;getline;getline;getline
hdisk1=hdisk1 $0;getline
val1=val1 $0;getline
hdisk1=hdisk1 $0;getline
val1=val1 $0;getline
hdisk1=hdisk1 $0;getline
val1=val1 $0;getline
hdisk1=hdisk1 $0;getline
val1=val1 $0;getline
print hdisk0
print val0
print hdisk1
print val1
}
'

the result is this :
File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
0,0 0,0 0,0 0,0 0,0 0,0
File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
0,0 0,0 0,0 0,0 0,0 0,0
File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
0,0 0,0 0,0 0,0 0,0 0,0
File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
0,0 0,0 0,0 0,0 0,0 0,0

thank you PHV

regards, pascal

RE: how to concate line in four variables or array

(OP)
Hi PHV,

it looks not working :(

done in MobaXterm
[10/06/2014 12:46.48] /drives/c/Tmp/CH Bergerac
[pch.PC-PCH] ➤ awk '/^hdisk/{h=$0;getline;v=$0;for(i=1;i<4;++i){getline;h=h";"$0;getline;v=v";"$0};print h"\n"v}' test.txt
; File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
; 0,0 0,0 0,0 0,0 0,0 0,0
; File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
; 0,0 0,0 0,0 0,0 0,0 0,0
; File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
; 0,0 0,0 0,0 0,0 0,0 0,0
; File d'attente : avgtime mintime maxtime avgwqsz avgsqsz sqfull
; 0,0 0,0 0,0 0,0 0,0 0,0

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close