![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| convert a pipe delimited file to a':" delimited file | priyanka3006 | Shell Programming and Scripting | 6 | 05-26-2009 10:53 AM |
| Converting Space delimited file to Tab delimited file | jeevs81 | UNIX for Dummies Questions & Answers | 16 | 02-26-2009 02:49 AM |
| Determining type of file | JWilliams | UNIX for Dummies Questions & Answers | 2 | 04-20-2007 03:14 AM |
| Determining file length | jbrubaker | UNIX for Dummies Questions & Answers | 1 | 07-07-2006 04:06 PM |
| Converting Tab delimited file to Comma delimited file in Unix | charan81 | Shell Programming and Scripting | 22 | 01-20-2006 09:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Determining position in a tab delimited file
hi, I want to determine the position of specific values over a cutoff.
So I have a string of values that are mainly negative in number and I want to print the rare few that are positive. Specifically I want to know the position of the value along the string. The position is based from right to left (the right most value is 1 etc..). At the same time it should ignore the UI's at the end. e.g. (note the file is tab delimited) Code:
name x -0.002 -92 -45 78.33 UI UI UI name y -9.55 -83.21 45 -9.34 UI UI UI Code:
name x 1 name y 2 ![]() |
|
||||
|
Hi,
Try this, Code:
#!/usr/bin/perl
while (<>) {
chomp $_;
@array = split;
print $array[0],"\t",$array[1],"\t";
$counter = 0;
for (reverse (@array)){
chomp;
if ( ! /UI/ ){
$counter ++ ;
if ($_ > 0 ) {
print $counter,"\t",$_,"\n";
}
}
}
}
Output Code:
name x 1 78.33 name y 2 45 |
|
||||
|
Is this homework or are you working on the same project than this poster?
parsing rows |
|
||||
|
hey this code works great but whenever it runs into a line with multiple positives, it gives an output that looks like this..
Code:
name x 1 78.33 1 56 name y 2 45 Code:
name x 1 78.33 name x 1 56 Code:
#!/usr/bin/perl
while (<>) {
chomp $_;
@array = split;
print $array[0],"\t",$array[1],"\t";
$counter = 0;
for (reverse (@array)){
chomp;
if ( ! /UI/ ){
$counter ++ ;
if ($_ > 0 ) {
print $counter,"\t","$_","\n";
}
}
}
}
|
|
||||
|
Modiefied, try this ..
Code:
#!/usr/bin/perl
while (<>) {
chomp $_;
@array = split;
print $array[0],"\t",$array[1],"\t";
$counter = 0;
for (reverse (@array)){
chomp;
if ( ! /UI/ ){
$counter ++ ;
if ($_ > 0 ) {
print $counter,"\t","$_","\n";
last;
}
}
}
}
Code:
name x -0.002 -92 -45 78.33 UI UI UI name y -9.55 -83.21 33 45 -9.34 UI UI UI Code:
name x 1 78.33 name y 2 45 |
|
||||
|
Quote:
Hey actually the original script worked better. So the output using the original script would give. Code:
name x 1 78.33 name y 2 45 3 33 name x 1 78.33 name y 2 45 name y 3 33 i have no clue how to add the name and y (or x) for the other values. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|