Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/awk -f
- NR == FNR && FNR == 1 {
- headers = $0
- empty_row = ""
- for (i = 0; i < NF; i++) {
- empty_row = "\t-" empty_row
- }
- next
- }
- # In file2 where we found hg38
- # We transform "hg38:Chr11:8823729," to "chr11:8823729"
- # And use that as a key in the array `found`
- NR == FNR && $4 ~ /^hg38:/ {
- extra = $4
- sub(/hg38:/, "", extra)
- sub(/Chr/, "chr", extra)
- sub(/,$/, "", extra)
- found[extra] = $0
- }
- # First line of file1
- # Print the existing headers and an additional column
- NR != FNR && FNR == 1 {
- print $0 "\t" headers
- next
- }
- # Subsequent lines of file1
- NR != FNR {
- printf $0
- key = $1 ":" $2
- if (key in found) {
- print "\t" found[key]
- } else {
- print empty_row
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement