help printing two consecutive columns, every twenty in a large matrix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help printing two consecutive columns, every twenty in a large matrix
# 8  
Old 03-15-2011
@danmero

Well I took your advice and went back to the statement that you referenced and everything seems to be behaving now! I don't know what I was getting to throw me off. However, I did notice that the setting the upper limit i<=NF also counted whitespace so I had to divide NF/2 to get the number of fields I originally wanted.

I have no idea what I did wrong, looking over my past examples, but it was probably something straight forward. I appreciate all of your help and list the code I used to get 400 fields at the beginning of each file, throughout the whole file iterating up by twenty and at the end of each file.

Start of file:
Code:
cut -d ' ' -f1-402 file >tmp

Interspersed throughout file:
Code:
awk -F' ' '{for(i=1;i<=NF/2;i+=20){printf "%s %s ", $i, $(i+1)};print ""} file > tmp

End of the file:
Code:
awk -F' ' '{printf "%s %s ",$1, $2};{for(i=NF-400;i<=NF;i++) printf "%s ", $i;print ""}' file > tmp

Thanks again for all of your help!

Last edited by Franklin52; 03-16-2011 at 06:30 AM.. Reason: Please use code tags
# 9  
Old 03-15-2011
Don't know Smilie I made my own data sample and I use my own logic.
Code:
# cut -d\  -f1-402 file | head -2 > newfile
# cat newfile
 1 id01 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 A20 A21 A22 A23 A24 A25 A26 A27 A28 A29 A30 A31 A32 A33 A34 A35 A36 A37 A38 A39 A40 A41 A42 A43 A44 A45 A46 A47 A48 A49 A50 A51 A52 A53 A54 A55 A56 A57 A58 A59 A60 A61 A62 A63 A64 A65 A66 A67 A68 A69 A70 A71 A72 A73 A74 A75 A76 A77 A78 A79 A80 A81 A82 A83 A84 A85 A86 A87 A88 A89 A90 A91 A92 A93 A94 A95 A96 A97 A98 A99 A100 A101 A102 A103 A104 A105 A106 A107 A108 A109 A110 A111 A112 A113 A114 A115 A116 A117 A118 A119 A120 A121 A122 A123 A124 A125 A126 A127 A128 A129 A130 A131 A132 A133 A134 A135 A136 A137 A138 A139 A140 A141 A142 A143 A144 A145 A146 A147 A148 A149 A150 A151 A152 A153 A154 A155 A156 A157 A158 A159 A160 A161 A162 A163 A164 A165 A166 A167 A168 A169 A170 A171 A172 A173 A174 A175 A176 A177 A178 A179 A180 A181 A182 A183 A184 A185 A186 A187 A188 A189 A190 A191 A192 A193 A194 A195 A196 A197 A198 A199 A200 A201 A202 A203 A204 A205 A206 A207 A208 A209 A210 A211 A212 A213 A214 A215 A216 A217 A218 A219 A220 A221 A222 A223 A224 A225 A226 A227 A228 A229 A230 A231 A232 A233 A234 A235 A236 A237 A238 A239 A240 A241 A242 A243 A244 A245 A246 A247 A248 A249 A250 A251 A252 A253 A254 A255 A256 A257 A258 A259 A260 A261 A262 A263 A264 A265 A266 A267 A268 A269 A270 A271 A272 A273 A274 A275 A276 A277 A278 A279 A280 A281 A282 A283 A284 A285 A286 A287 A288 A289 A290 A291 A292 A293 A294 A295 A296 A297 A298 A299 A300 A301 A302 A303 A304 A305 A306 A307 A308 A309 A310 A311 A312 A313 A314 A315 A316 A317 A318 A319 A320 A321 A322 A323 A324 A325 A326 A327 A328 A329 A330 A331 A332 A333 A334 A335 A336 A337 A338 A339 A340 A341 A342 A343 A344 A345 A346 A347 A348 A349 A350 A351 A352 A353 A354 A355 A356 A357 A358 A359 A360 A361 A362 A363 A364 A365 A366 A367 A368 A369 A370 A371 A372 A373 A374 A375 A376 A377 A378 A379 A380 A381 A382 A383 A384 A385 A386 A387 A388 A389 A390 A391 A392 A393 A394 A395 A396 A397 A398 A399
 2 id02 B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 B14 B15 B16 B17 B18 B19 B20 B21 B22 B23 B24 B25 B26 B27 B28 B29 B30 B31 B32 B33 B34 B35 B36 B37 B38 B39 B40 B41 B42 B43 B44 B45 B46 B47 B48 B49 B50 B51 B52 B53 B54 B55 B56 B57 B58 B59 B60 B61 B62 B63 B64 B65 B66 B67 B68 B69 B70 B71 B72 B73 B74 B75 B76 B77 B78 B79 B80 B81 B82 B83 B84 B85 B86 B87 B88 B89 B90 B91 B92 B93 B94 B95 B96 B97 B98 B99 B100 B101 B102 B103 B104 B105 B106 B107 B108 B109 B110 B111 B112 B113 B114 B115 B116 B117 B118 B119 B120 B121 B122 B123 B124 B125 B126 B127 B128 B129 B130 B131 B132 B133 B134 B135 B136 B137 B138 B139 B140 B141 B142 B143 B144 B145 B146 B147 B148 B149 B150 B151 B152 B153 B154 B155 B156 B157 B158 B159 B160 B161 B162 B163 B164 B165 B166 B167 B168 B169 B170 B171 B172 B173 B174 B175 B176 B177 B178 B179 B180 B181 B182 B183 B184 B185 B186 B187 B188 B189 B190 B191 B192 B193 B194 B195 B196 B197 B198 B199 B200 B201 B202 B203 B204 B205 B206 B207 B208 B209 B210 B211 B212 B213 B214 B215 B216 B217 B218 B219 B220 B221 B222 B223 B224 B225 B226 B227 B228 B229 B230 B231 B232 B233 B234 B235 B236 B237 B238 B239 B240 B241 B242 B243 B244 B245 B246 B247 B248 B249 B250 B251 B252 B253 B254 B255 B256 B257 B258 B259 B260 B261 B262 B263 B264 B265 B266 B267 B268 B269 B270 B271 B272 B273 B274 B275 B276 B277 B278 B279 B280 B281 B282 B283 B284 B285 B286 B287 B288 B289 B290 B291 B292 B293 B294 B295 B296 B297 B298 B299 B300 B301 B302 B303 B304 B305 B306 B307 B308 B309 B310 B311 B312 B313 B314 B315 B316 B317 B318 B319 B320 B321 B322 B323 B324 B325 B326 B327 B328 B329 B330 B331 B332 B333 B334 B335 B336 B337 B338 B339 B340 B341 B342 B343 B344 B345 B346 B347 B348 B349 B350 B351 B352 B353 B354 B355 B356 B357 B358 B359 B360 B361 B362 B363 B364 B365 B366 B367 B368 B369 B370 B371 B372 B373 B374 B375 B376 B377 B378 B379 B380 B381 B382 B383 B384 B385 B386 B387 B388 B389 B390 B391 B392 B393 B394 B395 B396 B397 B398 B399

Code:
# awk '{for(i=1;i<=NF;i+=20){printf "%s %s ", $i, $(i+1)};print ""}' newfile
1 id01 A19 A20 A39 A40 A59 A60 A79 A80 A99 A100 A119 A120 A139 A140 A159 A160 A179 A180 A199 A200 A219 A220 A239 A240 A259 A260 A279 A280 A299 A300 A319 A320 A339 A340 A359 A360 A379 A380 A399
2 id02 B19 B20 B39 B40 B59 B60 B79 B80 B99 B100 B119 B120 B139 B140 B159 B160 B179 B180 B199 B200 B219 B220 B239 B240 B259 B260 B279 B280 B299 B300 B319 B320 B339 B340 B359 B360 B379 B380 B399

PS. Please use [code] tags when posting data sample or code.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a subset of data from a large matrix

I do have a large matrix of the following format and it is tab delimited ch-ab1-20 ch-bb2-23 ch-ab1-34 ch-ab1-24 er-cc1-45 bv-cc1-78 ch-ab1-20 0 2 3 4 5 6 ch-bb2-23 3 0 5 ... (6 Replies)
Discussion started by: Kanja
6 Replies

2. Shell Programming and Scripting

Transform columns to matrix

The following code transform the matrix to columns. Is it possible to do it other way around ( get the input from the output) ? input y1 y2 y3 y4 y5 x1 0.3 0.5 2.3 3.1 5.1 x2 1.2 4.1 3.5 1.7 1.2 x3 3.1 2.1 1.0 4.1 2.1 x4 5.0 4.0 6.0 7.0 1.1 output x1 y1 0.3 x2 y1 1.2 x3... (1 Reply)
Discussion started by: quincyjones
1 Replies

3. Shell Programming and Scripting

Maybe by AWK: printing help diagonal matrix characters into line

Hi Experts, I want to print this charts diagonal data into straight lines. This is a matrix 24X24 Horizontal and vertical. - I want to print all the diagonal cutting characters into straight line: Data: E F S S A H A L L A T M C N O T S O B O D U Q H I W I B N L O C N I L N L A N S I N... (9 Replies)
Discussion started by: rveri
9 Replies

4. Shell Programming and Scripting

Square matrix to columns

Hello all, I am quite new in this but I need some help to keep going with my analysis. I am struggling with a short script to read a square matrix and convert it in two collumns. A B C D A 0.00 0.06 0.51 0.03 B 0.06 0.00 0.72 0.48 C 0.51 0.72 0.00 ... (7 Replies)
Discussion started by: EvaAM
7 Replies

5. Programming

Converting columns to matrix

Dear All I would like to convert columns to matrix For example my data looks like this D2 0 D2 0 1.0 D2 0 D2 1 0.308 D2 0 D2 2 0.554 D2 0 D2 3 0.287 D2 0 D2 4 0.633 D2 0 D2 5 0.341 D2 0 D2 6 0.665 D2 0 D2 7 0.698 D2 0 D2 8 0.625 D2 0 D2 9 0.429 D2 0 D2 10 0.698 D2 0 D2 11... (7 Replies)
Discussion started by: bala06
7 Replies

6. Shell Programming and Scripting

conversion: 3 columns into matrix

Hi guys, here https://www.unix.com/shell-programming-scripting/193043-3-column-csv-correlation-matrix-awk-perl.html I found awk script converting awk '{ OFS = ";" if (t) { if (l != $1) t = t OFS $1 } else t = OFS $1 x = x ? x OFS $NF : $NF l = $1 }... (2 Replies)
Discussion started by: grincz
2 Replies

7. Shell Programming and Scripting

Columns comparision of two large size files and printing the difference

Hi Experts, My requirement is to compare the second field/column in two files, if the second column is same in both the files then compare the first field. If the first is not matching then print the first and second fields of both the files. first file (a .txt) < 1210018971FF0000,... (6 Replies)
Discussion started by: krao
6 Replies

8. Shell Programming and Scripting

grep/fgrep/egrep for a very large matrix

All, I have a problem with grep/fgrep/egrep. Basically I am building a 200 times 200 correlation matrix. The entries of this matrix need to be retrieved from another very large matrix (~100G). I tried to use the grep/fgrep/egrep to locate each entry and put them into one file. It looks very... (1 Reply)
Discussion started by: realwindfly
1 Replies

9. Shell Programming and Scripting

extracting multiple consecutive columns using awk

Hello, I have a matrix 200*10,000 and I need to extract the columns between 40 and 77. I dont want to write in awk all the columns. eg: awk '{print $40, $41, $42,$43 ... $77}'. I think should exist a better way to do this. (10 Replies)
Discussion started by: auratus42
10 Replies

10. Linux

Regarding Dot Matrix Printing

Hi all, What I want is that can we manage printing a text file on a Dot Matrix printer installed on a Linux machine and the printer should not take the normal A4 format, but should print only to the extent the text file has text in it. What happen usually is that when we give print comand to any... (0 Replies)
Discussion started by: aman_mlt
0 Replies
Login or Register to Ask a Question