1
F gge0006y

D 12-30-2006

T 14:05:55

S a69

B 15.3

M gge06001

P 30.6

Q 21.1

R 1006.6

U 1014.6

X 36.1

A 38.994        0             0

G 107.71        0             0

H 8.433

O 36.705

C 7.621

K 27.623

W 210.51

I need to cut the both 0 0 from A and G but I cant seem to do it without cutting all zeros from the text which is not what I want, just those four zeros, how would I do this?

  • probably has flaws but sed 's/ 0//g' input or sed 's/0 0//g' input <=SE removed the extra spaces in there. – jesse_b Feb 11 '18 at 18:30
  • 3
    What's the rule? "Remove columns 2 and 3 if they exist?" or " ... if they exist and are 0"? or "if they exist on lines where column 1 is an A or G"? – Jeff Schaller Feb 11 '18 at 18:31
  • @cargoboom: Be wary of using my first suggestion. if any of your numbers start with a 0 it will give unwanted results. For example if you had: C 07.621 it would cut it to C 7.621 – jesse_b Feb 11 '18 at 18:39
  • 1
    Rather than cutting the fields you don't want, consider printing the fields that you do e.g. cut -d ' ' -f1,2 file or awk '{print $1, $2}' file – steeldriver Feb 11 '18 at 19:43
0

Assuming input is space delimited:

cut -d' ' -f 1-2 input

(This answer is the same as steeldriver's prior comment...)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.