1

I have file which contains data in columnwise manner. Please help me to get desired output. I have tried to use awk but not able to insert the value.

- A  B  C   D   E
- 6 15  78  4   
- 4 14  77  4   23
- 5 13  79  2   45
- 5 16  81  4   
- 5 16  81  4   65

I need to check if column E is blank, then if column A=6 then insert 240 in column E and A=5 then insert 120 and A=4 then insert 0 in blank space.

Expected Output:

- A B   C   D   E
- 6 15 78   4   240
- 4 14 77   4   0
- 5 13 79   2   120
- 5 16 81   4   120
- 5 16 81   4   120
2
  • 1
    Seems to me you're modifying E in any case, regardless of if it's empty?
    – ilkkachu
    Commented Jun 8, 2017 at 11:25
  • 1
    can we see what you tried? then we could lead you to the final answer (in a hopefully-understandable way)
    – Jeff Schaller
    Commented Jun 8, 2017 at 11:32

1 Answer 1

2

According to your expected output, the E field's emptiness does not make much influence.
It's enough to check A field value with following:

awk '{ if($2==6) $6=240; else if($2==5) $6=120; else if($2==4) $6=0 }1' file | column -t

The output:

-  A  B   C   D  E
-  6  15  78  4  240
-  4  14  77  4  0
-  5  13  79  2  120
-  5  16  81  4  120
-  5  16  81  4  120

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.