How to substract values in file in different colums from 1 ?
1
0
Entering edit mode
5 weeks ago

I have a file with arrangement shown below

A  0.5  0.2  0.4  0.8  0.3
B  0.2  0.8  0.7  0.0  0.6
C  0.8  0.2  0.1  0.4  0.7


And so on with around 8000 columns.

Now i don't know how to subtract these values in the column from 1 i.e.
Results

A  0.5  0.8  0.6  0.2  0.7
B  0.8  0.2  0.3  1.0  0.4
C  0.2  0.8  0.9  0.6  0.3


substraction awk • 309 views
0
Entering edit mode

Your post is confusing esp expected output.

0
Entering edit mode

Thank you for your quick suggestion.

So, if the input is like

A 0.4

Then what i want is

A 0.6

And that is 1-0.4 =0.6 .

Hope i cleared the confusion.

3
Entering edit mode
5 weeks ago

Let's suppose your values are stored in a file called file.txt. A simple awk command to achieve your objective would be:

awk '{for(i=2;i<=NF;i++){$i = 1 -$i}} {print \$0}' file.txt > output.txt


It basically loops all the columns (NF field) of each row starting from the second column, it substitutes their values with 1 - value and then prints the entire line.

0
Entering edit mode

Thanks for your valuable time and suggestion .This command works fine.