0

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in f1, the value in $1 is appended to it at the end of the line with a /test/id/$1_raw.file_fixed.txt. The $1 value is from f1 as well. Most of this is static text, except the value from $1 is after the third /. The lines that begin with R_2019 are just printed as is. The awk does execute but the output is unchanged. Thank you :).

I also tried another awk with no luck.

f1

xyxy_0268 0000-yyyy
xyxy_0270 1111-xxxx
R_0000_00_02_00_45_32_xxxx_x0-0000-100-x0.0_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx

f2

/path/to/the/xxx/data/0000-yyyy_v1_0000-yyyy_RNA_v1/190326-Control_v1_20190328071906449 
/path/to/the/xxx/data/00-0000_xxxx-03_v1/00-0000_xxxx-03_v1_20190322115521953
/path/to/the/xxx/data/1111-xxxx-03_v1/1111-xxxx-03_v1_20190322115521953

desired

xyxy_0268 0000-yyyy /path/to/the/xxx/data/0000-yyyy_v1_0000-yyyy_RNA_v1/190326-Control_v1_20190328071906449/test/id/xyxy_0268_raw.file_fixed.txt
xyxy_0270 1111-xxxx /path/to/the/xxx/data/1111-xxxx-03_v1/1111-xxxx-03_v1_20190322115521953/test/id/xyxy_0270_raw.file_fixed.txt
R_0000_00_02_00_45_32_xxxx_x0-0000-100-x0.0_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx

awk

awk 'NR==FNR {for(i=1; i<=NF; i++) id[$i]=$1; next} $2 in id{$3=id[$i] "/test/id/" $1 "_raw.file_fixed.txt"}1' f2 f1

awk 'NR==FNR {for(i=1; i<=NF; i++) id[$i]=$1; next} $2 in id{$3=id/$2/ "/test/id/" $1 "_raw.file_fixed.txt"}1' f2 f1

1 Answer 1

0
$ awk 'NR==FNR {a[$0]++; next} {for (i in a) if (i~$2 && $2 != "") {print $0" /test/id/"$2"_raw.file_fixed.txt"; next}} {print}' f2 f1
xyxy_0268 0000-yyyy /test/id/0000-yyyy_raw.file_fixed.txt
xyxy_0270 1111-xxxx /test/id/1111-xxxx_raw.file_fixed.txt
R_0000_00_02_00_45_32_xxxx_x0-0000-100-x0.0_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .