简体   繁体   中英

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

I have unique action to do. I have these two files:

file1:

something SOME.THING-AGAIN-WHATEVER.SUPPORT irrelevant_column3_text

file2:

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.

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...

I assume that this can be done using awk, but this is definitely beyond my skills... thanks in advance.

I was able to achive what I've wanted with simple grep and 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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