The two commands:
cat /tmp/OutFile | egrep "GAP" | awk '{print $10, $11}' | sort| uniq >> ${FILE}
cat /tmp/OutFile | egrep "DUP" | awk '{print $11, $12}' | sort| uniq >> ${FILE}
clearly can't produce the desired output since you are printing two whitespace-separated input fields when your output contains three whitespace-separated fields. Furthermore, you have two unneeded invocations of cat
, egrep
, and uniq
; one unneeded invocation of awk
and one or two unneeded invocations of sort
.
The following is an alternative to the code RudiC suggested that seems to do what you want with one invocation of awk
and one invocation of sort
:
awk '
/DUP/ { gsub(/[()]/, "", $13)
out[$11 " " $12 "\t" $13]
}
/GAP/ { gsub(/[()]/, "", $12)
out[$10 " " $11 "\t" $12]
}
END { printf("1st column\t2nd column\n")
for(line in out)
print line | "sort"
}' file
which (if file
contains one or more copies of the three sample input lines you showed us in post #1) produces the output:
1st column 2nd column
CL/U18 9P-NC CL90U8
CL/X18 8.5P-NC CL85W8
which contains a space separating the two input fields that make up the "1st column" output and a tab separating that from the single output field that makes up the "2nd column" output.
If you don't care about the order of lines in the output (and were just using sort | uniq
to get rid of duplicate lines of output instead of caring about the order of the output, delete the text in the script shown in red and it will run a little bit faster.
If you are trying this on a Solaris/SunOS system, change awk
in the script to /usr/xpg4/bin/awk
or nawk
.
It isn't clear to me whether you actually want those headings or not, but I included them since that is what you said you wanted. I assume that it is obvious that you can remove the printf
statement from my script above if you don't want the heading line in your output.