how to flip values of two columns and add an extra column

Hi guys,

Couldn't find the solution of this problem. Please Help!

I have a file-

Input_File

TC200232 92 30
TC215306 2 74
TC210135 42 14

I want an output file in which if column2>column3, the values are swapped and an additional column with value Rev_Com is added to those rows.

Output_File

TC200232 30 92 Rev_Com
TC215306 2 74
TC210135 14 42 Rev_Com

Thanks in advance.

awk '{if( $2 > $3) {tmp=$2; $2=$3;$3=tmp " Rev_Com";} print}' Input_File

On what criteria is row 2 spared out of it?

Thanks ranjithpr! Its working fine.

Hi zaxxon,

row two is spared out because its column2<column3.

awk :

awk '{
if($2>$3)
{
	t=$2
	$2=$3
	$3=t
	$4="Rev_Com"
	NF=4
}
	print
}' file

perl:

open FH,"<file";
while(<FH>){
	@arr=split(" ",$_);
	if ($arr[1]>$arr[2]){
		print $arr[0]," ",$arr[2]," ",$arr[1],"Rev_Com\n";
	}
	else{
		print $_;
	}
}
close FH;