从索引文件用awk搬迁串/ sed的 [英] Relocation strings using awk/sed from a index file
问题描述
我一直AP preciate所有从本网站有所帮助。我想搬迁的基础上从索引文件中的索引号的字符串。
I'd always appreciate all helps from this website. I would like to relocate strings based on the index number from an index file.
指数数字显示在索引文件(index.txt)的第一列,我想根据索引号搬迁路径。路径被放置在相同的行中,如果索引号是相同的。例如,有两个零,以便path_sparc_ifu_dec_in_3826被放置在第一行上,并path_sparc_ifu_dec_in_4349放置在第一行上,毗邻path_sparc_ifu_dec_in_3826
Index numbers are shown on the first column in the index file (index.txt) and I would like to relocate "path" based on index numbers. Paths are placed in the same row if the index number is the same. For example, there are two zeros so path_sparc_ifu_dec_in_3826 is placed on the first row and path_sparc_ifu_dec_in_4349 is placed on the first row and next to path_sparc_ifu_dec_in_3826.
index.txt:
index.txt:
0 path_sparc_ifu_dec_in_3826 str DR - -
0 path_sparc_ifu_dec_in_4349 stf DR - -
1 path_sparc_ifu_dec_in_2374 stf DR - -
1 path_sparc_ifu_dec_in_4011 stf DR - -
2 path_sparc_ifu_dec_in_3078 stf DR - -
不过,字符串都写在另一个文件(的Source.txt),每个路径有弦的四根线。
However, strings are written in another file (source.txt) and each "path" has four lines of strings.
的Source.txt:
source.txt:
path_sparc_ifu_dec_in_3826
dtu_inst_d[14]
dec_fcl_rdsr_sel_pc_d
0.8664
path_sparc_ifu_dec_in_4349
dtu_inst_d[18]
dec_swl_rdsr_sel_thr_d
0.795429
path_sparc_ifu_dec_in_2374
dtu_inst_d[13]
dec_dcl_cctype_d[2]
0.938914
path_sparc_ifu_dec_in_4011
dtu_inst_d[13]
ifu_exu_useimm_d
0.843643
path_sparc_ifu_dec_in_3078
dtu_inst_d[12]
ifu_exu_shiftop_d[2]
0.915818
所需的输出是:
path_sparc_ifu_dec_in_3826 path_sparc_ifu_dec_in_4349
dtu_inst_d[14] dtu_inst_d[18]
dec_fcl_rdsr_sel_pc_d dec_swl_rdsr_sel_thr_d
0.8664 0.795429
path_sparc_ifu_dec_in_2374 path_sparc_ifu_dec_in_4011
dtu_inst_d[13] dtu_inst_d[13]
dec_dcl_cctype_d[2] ifu_exu_useimm_d
0.938914 0.843643
path_sparc_ifu_dec_in_3078
dtu_inst_d[12]
ifu_exu_shiftop_d[2]
0.915818
我的想法是,(1)首先将两个文件和(2)使用索引号搬迁路径信息,但我不知道如何做到这一点的工作。也许,SED / AWK是一个合适的语言。
My idea is that (1)combining two files first and (2) relocate path info using the index number, but I don't know how to do this work. Probably, sed/awk is an appropriate language.
任何帮助是AP preciated。
Any help is appreciated.
最好的,
尹在
推荐答案
这是另一个code,对我的作品。
This is another code that works for me.
awk '
NR==FNR {T[$2] = $1
MX = $1
next
}
$1 in T {IX = T[$1]
}
{P[IX, (FNR+3)%4] = P[IX, (FNR+3)%4] "\t" $0
}
END {for (i=0; i<=MX; i++) for (j=0; j<4; j++) print P[i, j]
}
' index.txt source.txt
这篇关于从索引文件用awk搬迁串/ sed的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!