Sponsored Content
Full Discussion: Array manipulation with awk?
Top Forums Shell Programming and Scripting Array manipulation with awk? Post 302949589 by liuzhencc on Monday 13th of July 2015 04:01:21 PM
Old 07-13-2015
Quote:
Originally Posted by RudiC
For several files, you might try
Code:
paste file1 file2 | awk '
        {for (i=0; i<=1; i+=.1) print $1, $2+i*($6-$2), $3+i*($7-$3), $4+i*($8-$4) > "FILE"i}
' OFS="\t" OFMT="%12.8f"  CONVFMT="%3.1f"

The whole loop is in a single awk! Great! It's exactly what I expected.

---------- Post updated at 03:48 AM ---------- Previous update was at 02:13 AM ----------

Quote:
Originally Posted by RudiC
For several files, you might try
Code:
paste file1 file2 | awk '
        {for (i=0; i<=1; i+=.1) print $1, $2+i*($6-$2), $3+i*($7-$3), $4+i*($8-$4) > "FILE"i}
' OFS="\t" OFMT="%12.8f"  CONVFMT="%3.1f"

Why only '0' printed instead of 0.00000000 because we have OFMT="%12.8f"?
Code:
Fe       -0.01074510     -0.02593680    0
C         0.04575820     -0.73432250      1.64300310
C         0.04575820     -0.73432250     -1.64300310
C        -0.10666920      1.77790930    0
C         1.93027880     -0.01204220    0
O         0.04575820     -1.16885880      2.68430280
O         0.04575820     -1.16885880     -2.68430280
O        -0.17136180      2.92286450    0
O         2.96465800     -0.26870410    0
C        -1.80213220     -0.19964760    0
O        -2.93463550     -0.30532860    0

we want
Code:
Fe       -0.01074510     -0.02593680      0.00000000
C         0.04575820     -0.73432250      1.64300310
C         0.04575820     -0.73432250     -1.64300310
C        -0.10666920      1.77790930      0.00000000
C         1.93027880     -0.01204220      0.00000000
O         0.04575820     -1.16885880      2.68430280
O         0.04575820     -1.16885880     -2.68430280
O        -0.17136180      2.92286450      0.00000000
O         2.96465800     -0.26870410      0.00000000
C        -1.80213220     -0.19964760      0.00000000
O        -2.93463550     -0.30532860      0.00000000

---------- Post updated at 04:01 AM ---------- Previous update was at 03:48 AM ----------

Quote:
Originally Posted by RudiC
For several files, you might try
Code:
paste file1 file2 | awk '
        {for (i=0; i<=1; i+=.1) print $1, $2+i*($6-$2), $3+i*($7-$3), $4+i*($8-$4) > "FILE"i}
' OFS="\t" OFMT="%12.8f"  CONVFMT="%3.1f"

Use 'printf' does the trick.
Code:
paste feco5_s feco5_mecp | awk '{for (i=1; i<=9; i+=1) printf " %-10s   %12.8f    %12.8f   %12.8f\n", $1, $2+i/10*($6-$2), $3+i/10*($7-$3), $4+i/10*($8-$4) > "feco5_sm"i}'

Thanks a lot for this wonderful script.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk manipulation

Hi , what a wonderful command but so hard to maintain ! i have a file like that : 03/07/2006 05:58:45 03/07/2006 06:58:45 03/07/2006 07:58:50 03/07/2006 08:58:50 and i want to read it and keep only the lines with 3rd field less than 07:00:00 writing it in a second file ! ... (2 Replies)
Discussion started by: Nicol
2 Replies

2. Shell Programming and Scripting

File manipulation with awk

Could you please help me to achieve the below: In a file I need to convert the multiple lines whose filed 1 and field 5 values are same into a single line but with the field 4 values comma separed as mentioned below. Fileds after 5 shall be discarded. Also here by default all other remaining... (6 Replies)
Discussion started by: dhams
6 Replies

3. Shell Programming and Scripting

$0 manipulation in awk

OK, so if $0 represent the entire record... can I change $2 and will that be reflected back in $0? I think the following answers that YES, it does work. But is there anything I should be thinking about prior to doing this? What I am actually doing is part of 5 pages of scripting and awk... (1 Reply)
Discussion started by: joeyg
1 Replies

4. Shell Programming and Scripting

Array manipulation in perl

hi all, i am trying to append the output of a find command (for different paths)in an array as below... my $res_array; $i=0; $dir="/orn/ops/regs"; foreach $block("am","xb"){ $bdir="$dir/$block"; $res_array=`find $bdir ! -user mainuser -printf \"\%u \%h\\n\"`; $i++; } i... (6 Replies)
Discussion started by: saapa
6 Replies

5. Shell Programming and Scripting

Bash array manipulation

seeking assistance on comparing two arrays using bash: array1=(disk1, disk2, disk3, disk5, disk7, vol1, vol2, vol3, vol4, vol5) array2=(disk2, disk5 vol2, vol4 ) 1) if two arrays have same elements; EXIT else populate array3 & array4 with elements that are different between array1 & array2 as:... (3 Replies)
Discussion started by: solaix14
3 Replies

6. Shell Programming and Scripting

How to Assign an shell array to awk array?

Hello All, Can you please help me with the below. #!/bin/bash ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5 EXTRACT_DT:30-SEP-12 VER_NUM:1" ARR="No Differences In Stage Between HASH_TOTALS & HASH_TOTALS_COMP For UNINUM:0722075 PROVIDER:5... (14 Replies)
Discussion started by: Ariean
14 Replies

7. Shell Programming and Scripting

String manipulation using awk

I have the following string 512m512m I'm trying to split the string using awk awk '{ split(512m512m,a,"m") print $a; $a }' Sometimes the string could be 1024g1024g or 2048G2048G or 512M1024G how can i change the fieldsep to be a alphabet irrespective of case, and also... (8 Replies)
Discussion started by: ramky79
8 Replies

8. Shell Programming and Scripting

awk manipulation

Hallo Family, I have csv file which has over a million records in it. All i want to do is to change field 2 to have the same value as field 10. sample file:Now 0860093239,Anonymous,unconditional,+27381230283,Anonymous,unconditional,y,public,,2965511477:0A Desired output: ... (2 Replies)
Discussion started by: kekanap
2 Replies

9. Shell Programming and Scripting

awk manipulation

hello I have example file AA 11 BB 22 CC 33 And what I expect to have -a AA=11 -a BB=22 -a CC=33 can anyone help how I have this using awk? (1 Reply)
Discussion started by: vikus
1 Replies

10. Shell Programming and Scripting

awk manipulation

Hello all, Can someone help me with write part of code in awk to merge 2 files? Go through file1 check if number from column 3 exist in file2(column 2) if yes take value from column 1 and add to column 4 in file1. If value in column 4 exist in file1 skip it. file1... (2 Replies)
Discussion started by: vikus
2 Replies
All times are GMT -4. The time now is 02:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy