linux - Multi-input files for awk -


i have 2 csv files, first 1 looks below:

file1:

3124,3124,0,2,,1,0,1,1,0,0,0,0,0,0,0,0,1106,11 6118,6118,0,0,,0,0,1,0,0,0,0,1,1,1,1,1,5156,51 6679,6679,0,0,,1,0,1,0,0,0,0,0,1,0,1,0,1106,11 5249,5249,0,0,,0,0,1,1,0,0,0,0,0,0,0,0,1106,13 2658,2658,0,0,,1,0,1,1,0,0,0,0,0,0,0,0,1197,11 4322,4322,0,0,,1,0,1,1,0,0,0,0,0,0,0,0,1307,13 

file2:

7792,1307,2012-06-07,,,, 5249,4001,2016-07-02,,,, 6001,1334,2017-01-23,,,, 2658,4001,2009-02-09,,,, 9279,1326,2014-12-20,,,, 

what need: if $2 in file2 = 4001, has match $1 of file2 file1, if $18 in file1 = 1106 matched $1 print line.

the expected output:

5249,5249,0,0,,0,0,1,1,0,0,0,0,0,0,0,0,1106,13 

i have tried following, no success.

awk 'nr=fnr {a[$1]=$1;next} {print $1}' 

p.s: files compressed, have use zcat command

i try like:

$ cat t.awk begin { fs = "," }  # processing first file nr == fnr && $18 == 1106 { a[$1] = $0; next }  # processing second file $2 == 4001 && $1 in { print a[$1] }   $ awk -f t.awk file1.txt file2.txt 5249,5249,0,0,,0,0,1,1,0,0,0,0,0,0,0,0,1106,13 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -