![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grep all the columns based on a particular column | pmallur | UNIX for Advanced & Expert Users | 2 | 09-03-2008 04:51 PM |
| Convert two column data into 8 columns | NickC | Shell Programming and Scripting | 8 | 06-28-2008 12:19 PM |
| how to read the column and print the values under that column | gemini106 | Shell Programming and Scripting | 6 | 03-28-2008 07:05 AM |
| How to check Null values in a file column by column if columns are Not NULLs | Mandab | Shell Programming and Scripting | 7 | 03-15-2008 09:57 AM |
| replace a column values with the first value in column | sumeet | UNIX for Advanced & Expert Users | 3 | 02-06-2007 01:13 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. Last edited by smriti_shridhar; 10-17-2008 at 08:37 AM.. Reason: formatting |
|
||||
|
awk :
Code:
awk '{
if($2>$3)
{
t=$2
$2=$3
$3=t
$4="Rev_Com"
NF=4
}
print
}' file
Code:
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;
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|