Sponsored Content
Full Discussion: awk incorrect format
Top Forums Shell Programming and Scripting awk incorrect format Post 303025259 by Geneanalyst on Monday 29th of October 2018 02:50:03 PM
Old 10-29-2018
awk incorrect format

I was wondering whether anyone has any idea what is happening here. I'm using simple code to compare 2 tab delimited files based on column 1 values. If the column1 value of file1 exists in file2, then I'm to print the column4 value in file2 in column3 of file1. Here is my code:



1st I have to produce file1 by concatenating columns 4&5 of the input file:


INPUT FILE:


Code:
1    52828739    rs12044739    C    T
1    52835713    rs72899818    T    C
1    52836736    rs10157619    G    A
1    52844478    rs6684941    A    G

Using this simple code, I reorder columns in the INPUT file and concatenate columns 4 &5:
Code:
awk -F '\t' ' {print $3,$1,$2,$4$5}' OFS="\t" INPUT > file1

This produces the following file1 which looks fine:
Code:
rs12044739    1    52828739    CT
rs72899818    1    52835713    TC
rs10157619    1    52836736    GA
rs6684941    1    52844478    AG

This is file2:


Code:
rs12044739    1    52828739    CC
rs72899818    1    52835713    TC
rs10157619    1    52836736    GG
rs6684941    1    52844478    AA


Using the code:


Code:
awk 'NR == FNR {REP [$1] = $4; next} $1 in REP {$3 = REP[$1]} 1' OFS="\t" file2 file1 > results

Yields the following output file, RESULTS, which so far seems to look fine:


Code:
rs12044739    1    CC    CT
rs72899818    1    TC    TC
rs10157619    1    GG    GA
rs6684941    1    AA    AG

For final processing we need to print all rows for which column3 = column4. So I used this simple code:
Code:
awk -F '\t' '{ if ($3 = $4) print $0}'  OFS="\t" RESULTS > RESULTS2

Thus RESULTS2 should look like this:


Code:
rs72899818    1    TC    TC

Instead what I get is this:


Code:
rs72899818    1    TC    

TC

Any ideas as to what is causing the column4 value to print to the following row?

Last edited by Geneanalyst; 10-29-2018 at 05:01 PM.. Reason: forgot a step
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies

2. Shell Programming and Scripting

Awk incorrect data.

I am using the following command: nawk -F"," 'NR==FNR {a=$1;next} a {print a,$1,$2,$3}' file1 file2 I am getting 40 records output. But when i import file1 and file2 in MS Access i get 140 records. And i know 140 is correct count. Appreciate your help on correcting the above script (5 Replies)
Discussion started by: pinnacle
5 Replies

3. Shell Programming and Scripting

Merge lines in a file with Awk - incorrect output

Hi, I would like: FastEthernet0/0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored 0 output errors, 0 collisions, 0 interface resets Serial1/0:0 is up, line protocol is up 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort 0... (14 Replies)
Discussion started by: mv652
14 Replies

4. Shell Programming and Scripting

awk to extract incorrect fixed length records

I have a number of unix text files containing fixed-length records (normal unix linefeed terminator) where I need to find odd records which are an incorrect length. The data is not validated and records can contain odd backslash characters and control characters which makes them awkward to process... (2 Replies)
Discussion started by: methyl
2 Replies

5. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

6. Shell Programming and Scripting

awk : deleting specific incorrect lines

Hello friends, I searched in forums for similar threads but what I want is to have a single awk code to perform followings; I have a big log file going like this; ... 7450494 1724465 -47 003A98B710C0 7450492 1724461 -69 003A98B710C0 7450488 1724459 001DA1915B70 trafo_14:3 7450482... (5 Replies)
Discussion started by: enes71
5 Replies

7. Shell Programming and Scripting

wget format incorrect

I want to extract a web page to a temporary file as a source document. I tried: wget $webPgURL > /tmp/tmpfil but it says I have a missing URL. I have echoed $webPgURL just prior to the wget command and it is correct. If I use: firefox $webPbURL it brings up firefox with the correct page. Can... (3 Replies)
Discussion started by: slak0
3 Replies

8. Shell Programming and Scripting

awk sum giving incorrect value

cat T|awk -v format=$format '{ SUM += $1} END { printf format,SUM}' the file T has below data usghrt45tf:hrguat:/home/hrguat $ cat T -1363000.00123456789 -95000.00789456123 -986000.0045612378 -594000.0015978 -368939.54159753258415 -310259.0578945612 -133197.37123456789... (4 Replies)
Discussion started by: zulfi123786
4 Replies

9. Shell Programming and Scripting

Df -h | awk - output incorrect matching

Running solaris 9, on issuing the follwing command df -h | awk '$5 > 45 {print}' Filesystems with utilisation > 45% are being displayed as well as those between 5 and-9%!!! (3 Replies)
Discussion started by: squrcles
3 Replies

10. Shell Programming and Scripting

awk command gives incorrect result?

Hi All, I am looking to filter out filesystems which are greter than a specific value. I use the command df -h | awk '$4 >=70.00 {print $4,$5}' But this results out as below, which also gives for lower values. 9% /u01 86% /home 8% /u01/data 82% /install 70% /u01/app Looks... (3 Replies)
Discussion started by: jjoy
3 Replies
All times are GMT -4. The time now is 12:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy