Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to concate line in four variables or array

Status
Not open for further replies.

pchassang

Technical User
Jun 4, 2014
5
DE
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
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.​
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
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
 
Replace this:
hisdk0=hdisk0 $0
with this:
hdisk0=hdisk0 $0

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

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?
 
Again, what is your actual code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

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
 
What about this ?
Code:
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

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top