How to merge two commands


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to merge two commands
# 1  
Old 11-04-2011
How to merge two commands

I have input like
Code:
Unload: 2610000
225 2198
374 315
420 1149
57 2611
595 662
374 820
130 2938
486 2483
397 760

using these values, i need to divide first number with second number, means 225/2198, and using the value i'm trying to sort it. After sort i need first and "Unload" values, so i have written like this.
Code:
awk '{print ($1/$2),$1, $2}' b.in |sort

Output:
Code:
0.0218307 57 2611
0.0442478 130 2938
0.102366 225 2198
0.195731 486 2483
0.365535 420 1149
0.456098 374 820
0.522368 397 760
0.898792 595 662
0 Unload: 2610000
1.1873 374 315
-nan

from the output i need first line (0.0218307 57 2611) and (0 Unload: 2610000
) lines. How to write a command for that?

I have tried something like this,
Code:
awk '{print ($1/$2),$1, $2}' b.in |sort | (head -1;grep 'Unload')

It is giving only the 1st line. So how to reach that.

Last edited by Scott; 11-04-2011 at 08:22 AM.. Reason: Removed formatting; added code tags
# 2  
Old 11-04-2011
use this
Code:
awk '{print ($1/$2),$1, $2}' b.in | sort -n | head -2


Last edited by smilesavvy; 11-04-2011 at 07:40 AM..
# 3  
Old 11-04-2011
Took your output file content as an infile
Code:
$ nawk 'NR==1;/Unload/{print $0}' infile
0.0218307 57 2611
0 Unload: 2610000

This User Gave Thanks to jayan_jay For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Merge .lo into .so

Good day to everyone. I've built an libxml2 from sources. I can not install it in a proper way with using repository due to I have not sudo privilegies. I've got a set of .lo files. Is there a simple way to merge it in one .so or .a file? (2 Replies)
Discussion started by: z7ql
2 Replies

2. Shell Programming and Scripting

How to merge two files?

Hi Gurus, I have two files as below file1 abc cde cdd cdf file2 123 234 345 456 I want to get abc 123 cde 234 cdd 345 (3 Replies)
Discussion started by: ken6503
3 Replies

3. Shell Programming and Scripting

Merge output of 2 commands into variable

I am extracting two pieces of information from the following file: /proc/cpuinfo, that I need to merge into one report. The first command: grep -i processor /proc/cpuinfo | awk '{print $1$2,$3}' yields: processor: 0 processor: 1 processor: 2 processor: 3 The second command: grep -i... (4 Replies)
Discussion started by: jamarsh
4 Replies

4. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

5. Shell Programming and Scripting

merge two file

how to merge two file, i have 2 input file; file_1 & file_2, so i want the output file_3 as below file_1 NAME aa 111 222 bb.txt 111 222 cc 111 111 dd 222 ee 111 222 (4 Replies)
Discussion started by: zulabc
4 Replies

6. Shell Programming and Scripting

merge files

hi, i've two files whcih i need to merge in below format. File1- DEFINE lc_driver CHAR(3) INITIALIZE gr_XXX_MAIN_TABLE_XXX.* TO NULL { EXECUTE p_XXX_MAIN_TABLE_XXX_ins USING gr_XXX_MAIN_TABLE_XXX.* } File2 - # field1 LET table1.field1= (8 Replies)
Discussion started by: dvah
8 Replies

7. UNIX for Dummies Questions & Answers

awk simple commands merge

Is there nice awk code for merging the following commands and do the last task? input1 ab100 xxx 100 blahblah + 1000 ab100 yyy 90 blahblah + 1000 ef390 ggg 200 blahblah - 2000 ef390 aaa 100 blahblah - 2000 df888 ttt 300 ... (5 Replies)
Discussion started by: ruby_sgp
5 Replies

8. Shell Programming and Scripting

Merge all commands into one

how can i merge follwoing process to one... tail +5 rawdata_AAA_1.txt_$$ | grep -v "^$" >> rawdata_AAA_2.txt_$$ For discarding first 5 rows and deleting null rows awk '!/^ /{if(a) print a; a=$0}/^ /{print a}' rawdata_AAA_2.txt >> rawdata_AAA_3.txt For merging record if it split into 2 rows... (8 Replies)
Discussion started by: Amit.Sagpariya
8 Replies

9. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

10. Programming

code that reads commands from the standard i/p and executes the commands

Hello all, i've written a small piece of code that will read commands from standard input and executes the commands. Its working fine and is execting the commands well. Accepting arguments too. e.g #mkdir <name of the directory> The problem is that its not letting me change the directory i.e... (4 Replies)
Discussion started by: Phrozen Smoke
4 Replies
Login or Register to Ask a Question