CLI结合了两个不同文件中的两个不平衡列表
我一直在寻找一种结合两个不平衡文件的方法,我知道有一个解决方案,但我无法对其进行修改以满足我的需求。 IE
文件1
a
b
c
d
文件2
1
2
解决方案
a:1
b:2
c:1
d:2
如果第一个文件是10个单词,而第二个单词仅为3个单词,请重复3个单词,直到第一个文件eof的末尾,并且在其中确定有一个定界符标志。
我最好的尝试是:
paste -d file1 /dev/null file2 > new_file
但这只会使1,2列入新列表,但没有重复。
I was looking for a way to combine two files that are uneven, I know there is a solution with awk but I am unable to modify it to fit my need. I.E.
File 1
a
b
c
d
File 2
1
2
Solution
a:1
b:2
c:1
d:2
if the first file is 10 words and the second is only 3 words, repeat the 3 words until the end of the first file EOF, and im sure theres a delimiter flag with ':' in there.
My best attempt was:
paste -d file1 /dev/null file2 > new_file
But that only put the 1,2 in the new list but didn't repeat.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于给定的示例数据,您可以尝试此
awk
:For the given sample data, you may try this
awk
:使用您显示的样本,请尝试以下
AWK
代码。说明: 添加上述代码的详细说明。
With your shown samples, please try following
awk
code.Explanation: Adding detailed explanation for above code.
这可能对您有用(gnu sed):
用file2的内容准备保留空间。
将file2附加到当前行,用
:
替换第一个newline,然后仅打印第一行。回到保持空间并循环第一行。
删除当前行并重复。
使用Yes and粘贴的替代性:
或没有SED:
NB最终
-
表示循环文件的内容。This might work for you (GNU sed):
Prep the hold space with the contents of file2.
Append file2 to the current line, replace the first newline with
:
and print only the first line.Go back to the hold space and cycle the first line.
Delete the current line(s) and repeat.
Alternative using yes and paste:
or without sed:
N.B. The final
-
represents the contents of the cycled file2.