LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-11-2008, 12:30 AM   #1
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Rep: Reputation: 15
maximum value using perl or awk!!


hi,

I am working on RHEL 4ES. I have two columns like

8 9
7 4
5 3
10 12
6 5
----
---
i want a third column maximum value of the two columns... like

8 9 9
7 4 7
5 3 5
10 12 12
6 5 6
-----
-----

give me solution with AWK and perl.....

Thank you in advance..
 
Old 04-11-2008, 02:42 AM   #2
elthox
Member
 
Registered: Oct 2006
Posts: 41

Rep: Reputation: 15
Quote:
Originally Posted by visitnag View Post
hi,

I am working on RHEL 4ES. I have two columns like

8 9
7 4
5 3
10 12
6 5
----
---
i want a third column maximum value of the two columns... like

8 9 9
7 4 7
5 3 5
10 12 12
6 5 6
-----
-----

give me solution with AWK and perl.....

Thank you in advance..
HI,

Suppose you have these coloumns in numbers.txt. So,

cat numbers.txt|awk '{if($1>$2) {print $1,$2,$1}else{print $1,$2,$2}}'

Thats all!
 
Old 04-11-2008, 01:38 PM   #3
visitnag
Member
 
Registered: Mar 2008
Posts: 147

Original Poster
Rep: Reputation: 15
thanks... you have opened my eyes!!!!!!!!!!!!
 
Old 04-11-2008, 01:51 PM   #4
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by elthox View Post
HI,

Suppose you have these coloumns in numbers.txt. So,

cat numbers.txt|awk '{if($1>$2) {print $1,$2,$1}else{print $1,$2,$2}}'

Thats all!
I call UUOC!

awk can take a file name as input, so there's no need to lanuch a separate instance of cat, just to get awk to read the files:
Code:
awk '{if($1>$2) {print $1,$2,$1}else{print $1,$2,$2}}' numbers.txt > outputfile.txt
That achieves the same result without spawning an unneeded process.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
calling awk commands in perl script bharatbsharma Other *NIX 3 11-02-2007 08:07 PM
calling awk commands in perl script bharatbsharma Programming 6 11-02-2007 11:23 AM
awk/perl script for extract data mruknown1 Programming 3 09-11-2007 10:19 AM
awk/perl script for extract data mruknown1 Linux - Newbie 2 09-11-2007 05:42 AM
SED, AWK or PERL HELP embsupafly Programming 6 08-20-2005 10:07 PM


All times are GMT -5. The time now is 06:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration