Skip to main content
1 of 3
Chris Davies
  • 128.1k
  • 16
  • 178
  • 323

What you have lost is the trailing ) on your stdin subclause. What I suspect you have gained is a headache trying to read your code.

Try this instead, which then lends itself to further optimisation because it's (more) readable:

sort -k1,1 file2 |
    tr '[:blank:]' $'\t' |
    awk '
        BEGIN { FS="\t"; OFS="\t" }
        { if ($2 == "u") print $0, $1; else print $0, $3 }
    ' |
    awk '
        { gsub(/ /,"\t"); l=$4; sub(/.*_/,"",l); print $2 "\t" $3 "\t" l }
    ' |
    join -t $'\t' -a1 -e "u" -1 1 -2 1 -o 1.1,2.1,2.2 file1 - >out
Chris Davies
  • 128.1k
  • 16
  • 178
  • 323