简体   繁体   English

带有列值的“grep”并附加新列 bash/awk/grep?

[英]"grep" with column value and attach new column bash / awk /grep?

I have unique action to do.我有独特的行动要做。 I have these two files:我有这两个文件:

file1:文件 1:

something SOME.THING-AGAIN-WHATEVER.SUPPORT irrelevant_column3_text

file2:文件2:

SOMETHING-NEW-SOME-THING-AGAIN-WHATEVER-SUPPORT

Column 2 from file1 (SOME.THING....) is very similar to column in filre2 (SOMETHING...), except that: - it has dots instead of dashes - it misses some parts of a text from the beggining and the end. file1 (SOME.THING....) 中的第 2 列与 filre2 (SOMETHING...) 中的列非常相似,不同之处在于: - 它有点而不是破折号 - 它错过了开头和结尾。

What I want to get is this:我想得到的是这样的:

something SOME.THING-AGAIN-WHATEVER.SUPPORT irrelevant_column3_text SOMETHING-NEW-SOME-THING-AGAIN-WHATEVER-SUPPORT

So four column file, with attached in correct place input from file2...所以四列文件,附加在正确的地方从file2输入...

I assume that this can be done using awk, but this is definitely beyond my skills... thanks in advance.我认为这可以使用 awk 来完成,但这绝对超出了我的技能......提前致谢。

I was able to achive what I've wanted with simple grep and echo :)我能够通过简单的 grep 和 echo 实现我想要的:)

for i in $(file1 ); do echo -n "$i " ; grep $(echo $i|awk '{print $1}' |sed s'/\./-/g') file2;done 

Hope that helps to someone.希望对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM