Why its printing like this?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Why its printing like this?
# 1  
Old 06-24-2013
Why its printing like this?

Hi,
when i use the following awk i will get the output like double time printed values and the 2nd time only its giving data,
please help me to find this
for ex: awk code:
Code:
file_name=$1
file_name1=$2
ctn=$(awk 'FNR==NR{a[$2]=$4;}$2 in a{t=a[$2]-$4;print $2,(FNR==1)?"":t"@"}' ${file_name} ${file_name1})
echo $ctn > result.tsv
sed -i 's|@|\n|g' result.tsv
sed -i 's|^ ||g' result.tsv

file.tsv
Code:
10787	10026700	sb	267.00	228.88
11485	10056416	sb	22.61	0
11416	10073755	sb	29.23	0
10879	10098634	sb	58.99	0
10674	10153713	sb	99.88	0
11462	10216854	sb	44.97	0
10793	10233900	sb	0	0
11504	10251332	sb	69.98	0
10890	10295983	sb	39.97	0
10881	10335174	sb	69.96	0
11531	10339632	sb	65.00	0
11532	10339655	sb	115.00	0
11533	10339656	sb	145.00	0
10753	10339974	sb	199.98	0
10547	10543801	sb	19.97	0
10894	10598332	sb	224.54	0
10694	10629144	sb	279.00	0
11438	10629145	sb	500.00	0
10899	10669752	sb	219.00	199.00

file1.tsv
Code:
10787	10026700	sa	267.00	228.88
11485	10056416	sa	22.61	0
11416	10073755	sa	29.74	0
10879	10098634	sa	58.99	0
10674	10153713	sa	99.88	0
11462	10216854	sa	44.97	0
10793	10233900	sa	0	0
11504	10251332	sa	0	0
10890	10295983	sa	39.97	0
10881	10335174	sa	69.96	0

result.tsv
Code:
10026700 10056416 0
10073755 0
10098634 0
10153713 0
10216854 0
10233900 0
10251332 0
10295983 0
10335174 0
10339632 0
10339655 0
10339656 0
10339974 0
10543801 0
10598332 0
10629144 0
10629145 0
10669752 0
10026700 10056416 0
10073755 -0.51
10098634 0
10153713 0
10216854 0
10233900 0
10251332 69.98
10295983 0
10335174 0

---------- Post updated at 04:50 PM ---------- Previous update was at 04:46 PM ----------

it should print the 2nd col value with the result value which is 4th col. Comparison (if it find 10056416 in file1.tsv then sub the 22.61 - 22.61 print the 0 value)

Last edited by vbe; 06-24-2013 at 08:29 AM.. Reason: missing code tag
# 2  
Old 06-24-2013
I think you messed up the solutions presented to you in previous threads. Recheck carefully and find the answer yourself. The result file is exactly what I'd expect from your awk script.
# 3  
Old 06-24-2013
Hi RudiC,

when we do in putty or cmd prom. its giving perfect ans. But if I want it in .tsv file its giving like this. Please try it.
# 4  
Old 06-24-2013
I don't need to try it - I can see the error. Why don't you check previous proposals and find the error yourself?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Printing, SYSPRINTER, IP printing

Dear readers, We have a printer problem with a UNIX system. The OS is Unix IRIX 6.5 We have connected a printerto the system. If we then make a test print everything goes well . (IP printing) But if we make a print from the "orrga,i"program. Then we see all the printouts stuck within the... (3 Replies)
Discussion started by: SergevdH
3 Replies

2. UNIX for Dummies Questions & Answers

Sco Unix printing : jobs hangs in queue - printing via lp versus hpnpf

Hi, We have a Unix 3.2v5.0.5. I installed a printer via scoadmin, HP network printer manager with network peripheral name (hostname and ipadres are in /etc/hosts). This is the configuration file : Code: root@sco1 # cat configurationBanner: on:AlwaysContent types: simpleDevice:... (0 Replies)
Discussion started by: haezeban
0 Replies

3. Windows & DOS: Issues & Discussions

Linux to Windows Printing: PDF starts printing from middle of page.

We are using Red Hat. We have a issue like this: We want to print from Linux, to a printer attached to a Windows machine. What we want to print is a PDF. It prints, but the printing starts from the middle of the page. In the report, there is no space at the top but still printing starts from the... (5 Replies)
Discussion started by: rohan69
5 Replies

4. UNIX for Advanced & Expert Users

printing \n

Hi all, In a script I need to print a string: print "\n"; but i am not able to print the above mentioned string... Please help. Regards Rochit (5 Replies)
Discussion started by: rochitsharma
5 Replies

5. Shell Programming and Scripting

Printing

Hey, I'm trying to print in HP laserjet 2420 by using the command: lp -olandscape (file) For some reason it does not come out as landscape but as portrait. Help please. 10x. P.S. I'm using csh (0 Replies)
Discussion started by: Kofiko
0 Replies

6. UNIX for Dummies Questions & Answers

Printing

How do I configure a UNIX printer to print to a Windows PC with vt320 emulation (0 Replies)
Discussion started by: sowlix
0 Replies

7. UNIX for Dummies Questions & Answers

printing

whenever i print a file in UNIX the bottom line gets cut off i was wondering is there any way to fix this? thanks (2 Replies)
Discussion started by: hiei
2 Replies

8. UNIX for Dummies Questions & Answers

Printing

Ok, I found this http://docs.sun.com/?q=netstandard&p=/doc/805-7229/6j6q8svb1&a=view and I am trying to follow the section labled How To Add A Network Printer Using LP Commands But I just can't get these things to print (SUN hardware). We have an NT print server or I could print directly... (1 Reply)
Discussion started by: bbrandeb49
1 Replies

9. UNIX for Advanced & Expert Users

Printing Problems in unix ... ( Bar-cdoe - Ip Printing)

Hi guys ... i need ur help with some printing problem in unix ... first prob. : i wanna print from my NCR unix to an Win NT , Ip based printing server ( HP JetDirect ) . My issue , is it possible to print directly to an Ip address from unix ? How do i make it work to get any results ?... (3 Replies)
Discussion started by: QuickSilver
3 Replies

10. UNIX for Dummies Questions & Answers

Printing

Do all UNIX systems have the ability to print to an ASCII file? If so, is this a common thing to do, for reports or other output? Thank you for your response. (3 Replies)
Discussion started by: SYMTRAX
3 Replies
Login or Register to Ask a Question