awk output is space delimeted not tab delimeted


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk output is space delimeted not tab delimeted
# 1  
Old 09-07-2016
awk output is space delimeted not tab delimeted

In the below awk the output is space delimited, but it should be tab delimited. Did I not add the correct -F and OFS? Thank you Smilie.

The input file are rather large so I did not include them, but they are tab-delimeted files as well.


awk
Code:
awk -F'\t' -v OFS='\t' 'FNR==1 { next }
>       FNR == NR { file1[$2,$4,$5] = $2 " " $4 " " $5 }
>       FNR != NR { file2[$2,$4,$5] = $2 " " $4 " " $5 }
>       END { print "Match:"; for (k in file1) if (k in file2) print file1[k] # Or file2[k]
>             print "Missing in Reference but found in IDP:"; for (k in file2) if (!(k in file1)) print file2[k]
>             print "Missing in IDP but found in Reference:"; for (k in file1) if (!(k in file2)) print file1[k]
>       }' file1 file2 > out

current output (all in one field $1)
Code:
Match:
68521889 C T
167099158 A G
Missing in Reference but found in IDP:
93521604 A G
166903445 T C
Missing in IDP but found in Reference:
166210776 C T
147183143 A G

desired output (in 3 fields $1 $2 $3)
Code:
$1       $2 $3
Match:
68521889  C   T
167099158  A G
Missing in Reference but found in IDP:
93521604  A   G
166903445 T   C
Missing in IDP but found in Reference:
166210776 C   T
147183143 A G


Last edited by cmccabe; 09-07-2016 at 12:07 PM.. Reason: fixed format
# 2  
Old 09-07-2016
Hello cmccabe,

Could you please try to change following into your mentioned code. It should fly then.
Code:
FNR == NR { file1[$2,$4,$5] = $2 FS $4 FS $5 }
FNR != NR { file2[$2,$4,$5] = $2 FS $4 FS $5 }

I had changed " "with FS above, please do let us know how it goes then.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 09-07-2016
I total missed that, thank you very much Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk printing leading tab in output

The awk below executes and produces the current output. it skips the header in row 1 and prints $4,$5,$6 and then adds the header row back. The problem is that it keeps the tailing tab and prints it in front of $1. I could add a pipe to remove the tab, but is there a better way to do it with on... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

awk to add tab to output of both conditions

In the below awk written by @RavinderSingh13 I have added a few lines and am trying to have the output be tab-delimited. The input is space-delimeted and the portion in bold seems to add a tab to the Not found but not the found. Thank you :). file1 One 1 Two 2 Three 3 file2 One 1... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk output seperated by tab

I am just trying to output the below awk separated by tabs. Thank you :). awk (added OFS as an attempt to itroduce tabs) awk '{split($5,a,"-"); OFS='\t' print $1,$2,$3,a}' file.bed > test.bed The awk runs and produces all the data in 1 field instead of 4 fields. current output ... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Output file with <Tab> or <Space> Delimited

Input file: xyz,pqrs.lmno,NA,NA,NA,NA,NA,NA,NA abcd,pqrs.xyz,NA,NA,NA,NA,NA,NA,NA Expected Output: xyz pqrs.lmno NA NA NA NA NA NA NA abcd pqrs.xyz NA NA NA NA NA NA NA Command Tried so far: awk -F"," 'BEGIN{OFS=" ";} {print}' $File_Path/File_Name.csv Issue:... (5 Replies)
Discussion started by: TechGyaann
5 Replies

5. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

6. Shell Programming and Scripting

output - tab formatted - awk

Dear All, Good Day. I would like to hear your suggestions for the following problem: I have a file with 5 columns with some numbers in 16 lines as shown below. Input file: Col 1 Col 2 Col 3 Col 4 Col 5 12 220 2 121 20 234 30 22 9... (3 Replies)
Discussion started by: Fredrick
3 Replies

7. Shell Programming and Scripting

Awk to find space and tab.

Wants to print line when there exist leading or trailing space or tab in fields 2,3 and 5 The below code prints all lines in file even if they dont have leading and trailing space or tab. nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^*" || $i ~ "*$")}}1' file file Ouput required: ... (5 Replies)
Discussion started by: pinnacle
5 Replies

8. UNIX for Advanced & Expert Users

converting a .txt file to comma delimeted file

Dear all, I have a file with 5L records. one of the record in the file is as shown below. MARIA THOMAS BASIL 1000 FM 1111 MD ... (1 Reply)
Discussion started by: OSD
1 Replies

9. Shell Programming and Scripting

converting .txt to comma delimeted file

Dear all, I have a file with 5L records. one of the record in the file is as shown below. MARIA THOMAS BASIL 1000 FM 1111 MD GHANA YY 77354 4774 99999999 1234567 I need to convert this record in below format "","","","","MARIA","THOMAS","BASIL","","1000 FM 1111 MD","STE... (1 Reply)
Discussion started by: OSD
1 Replies

10. Shell Programming and Scripting

space in output from awk command

Hi I have tried this command cat /etc/passwd | awk -F: '{print$5}' note that the $5 is the column that displays full name- i.e. Kevin Kambell To the point, my output is fine except one thing I do not understand that some of output lines have space in front of them which I checked in... (7 Replies)
Discussion started by: lalelle
7 Replies
Login or Register to Ask a Question