Awk not printing the last combined column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk not printing the last combined column
# 1  
Old 05-08-2009
Awk not printing the last combined column

Code:
nawk -F "|" 'FNR==NR {a[$1]=$2 OFS $3 OFS $4 OFS $5 OFS $6;next}\
{if ($5 in a)print $1,"test",$5,a[$5], $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 ; \
else print $1,"Database",$5 OFS OFS OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 }' OFS="|" \
file1 file2 > file3

This works fine except the last part where
Code:
$2-$3-$4

i want to print $2$3$4 in one field seperated by -
it is printing 0

Appreciate help
# 2  
Old 05-08-2009
why do you think it's doing that?
# 3  
Old 05-08-2009
Quote:
Originally Posted by vgersh99
why do you think it's doing that?
I think i should use printf but i am not aware how to use it while printing an array.

I dont know why it is doing that.
# 4  
Old 05-08-2009
Hint: Is '-' a 'dash' or a 'minus' in your context?
# 5  
Old 05-08-2009
Quote:
Originally Posted by zenith
Code:
nawk -F "|" 'FNR==NR {a[$1]=$2 OFS $3 OFS $4 OFS $5 OFS $6;next}\
{if ($5 in a)print $1,"test",$5,a[$5], $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 ; \
else print $1,"Database",$5 OFS OFS OFS OFS OFS OFS $2,$3,$4 OFS OFS OFS OFS OFS OFS OFS OFS $2-$3-$4 }' OFS="|" \
file1 file2 > file3

This works fine except the last part where
Code:
$2-$3-$4

i want to print $2$3$4 in one field seperated by -
it is printing 0

Appreciate help
use $2"-"$3"-"$4 instead or it will be treated as minus and try to substract.
# 6  
Old 05-08-2009
Quote:
Originally Posted by vgersh99
Hint: Is '-' a 'dash' or a 'minus' in your context?

Actually i was about to post

i myself also figured it out and used
Code:
$2"-"$3"-"$4

Thanks vgersh99 and devtakh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: printing column using for loop

Hello: I've input data: Input data --- 3:60069:C:T 60069 C T 1 0 0 1 0 0 1 0 0 1 0 0 1 --- 3:60079:A:G 60079 A G 1 0 0 0.988 0.012 0 1 0 0 1 0 0 1 --- rs186476240:60157:G:A 60157 G A 1 0 0 1 0 0 1 0 0 1 0 0 1 I edit/make first few columns before numbers (6th column) and want to... (4 Replies)
Discussion started by: genome
4 Replies

2. Shell Programming and Scripting

Spacing off when files combined using awk or cat

I have 133 .txt files in a directory that I am combining into 1 file. The problem is when I use awk or cat to combine the files I get out put like this: output 85 138662360 KCNT1 86 138662962 KCNT1 82 138657053 KCNT1 83 138657635 KCNT1 95 138646881 KCNT1... (12 Replies)
Discussion started by: cmccabe
12 Replies

3. Shell Programming and Scripting

Combined sed+awk for lookup csv file

have written a combined sed+awk to perform a lookup operation which works but looking to enhance it. looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so: cat foo make,model,engine,trim,value... (6 Replies)
Discussion started by: jack.bauer
6 Replies

4. Shell Programming and Scripting

awk combined with an IF

Hi everybody! I try to printout a csv-file with the exeption of cell $1 and $4. what i tried so far: awk '{for(i = 1; i<=NF; i++);if(i == 1 || i == 4);else print($i)}' file.csv ..any ideas how it work and why my example fails? Thanks in advance! IMPe (3 Replies)
Discussion started by: IMPe
3 Replies

5. UNIX for Dummies Questions & Answers

Extracting combined differences based on a single column

Dear All, I have two sets of files. File 1 can be any number between 1 and 20 followed by a frequency of that number in a give documents... the lines in the file will be dependent to the analysed document. e.g. file1 1,5 4,1 then I have file two which is basicall same numbers but with... (2 Replies)
Discussion started by: A-V
2 Replies

6. Shell Programming and Scripting

Column printing in awk

Experts, i have a following file containing data in following manner. 1 2480434.4 885618.6 0.00 1948.00 40.00 1952.00 ... (6 Replies)
Discussion started by: Amit.saini333
6 Replies

7. Shell Programming and Scripting

awk: printing newline with last column

I was trying to simplify this from what I'm actually doing, but I started getting even more confused so I gave up. Here is the content of my input file: Academic year,Term,Course name,Period,Last name,Nickname 2012-2013,First Semester,English 12,7th Period,Davis,Lucille When I do this: ... (3 Replies)
Discussion started by: nextyoyoma
3 Replies

8. Shell Programming and Scripting

Printing another column using awk and input data

Hi, I have data of the following type, chr1 234 678 39 852 638 abcd 7895 chr1 526 326 33 887 965 kilj 5849 Now, I would like to have something like this chr1 234 678 39 852 638 abcd 7895 <a href="http://unix.com/thread=chr1:234-678">Link</a> chr1 526 326 33 887 965 kilj 5849 <a... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

9. Shell Programming and Scripting

Printing a variable column using awk

Hi everyone, Ok here's the scenario. I have a control file like this. component1,file1,file2,file3,file4,file5 component2,file1,file2,file3,file4,file5I want to do a while loop here to read all files for each component. file_count=2 while ] do file_name=`cat list.txt | grep... (2 Replies)
Discussion started by: The Gamemaster
2 Replies

10. Shell Programming and Scripting

Printing 1st column to lower case using awk

I want to print the 1st field in a comma seperated file to lower case and the rest the case they are. I tried this nawk -F"," '{print tolower($0)}' OFS="," file this converts whole line in to lower case i just want the first column to be converted. The below doesnt work because in... (11 Replies)
Discussion started by: pinnacle
11 Replies
Login or Register to Ask a Question