0

I want to delete characters after "." in the first column of my file, which looks like this:

location    LR  alpha
14884399.000000 0.471193    3.029710e+01
14904434.024291 0.440564    1.300841e-05
14924469.048583 0.356903    1.329721e-05

I want it to look like this:

location    LR  alpha
14884399    0.471193    3.029710e+01
14904434    0.440564    1.300841e-05
14924469    0.356903    1.329721e-05

I have tried these 2, they work but delete the second and the third columns:

echo ${input_var} | sed 's/\.[^ ]*/ /g' chr22.E.Asia.clrout

cat chr22.E.Asia.clrout | sed chr22.E.Asia.clrout col=1 's/\.[^ ]*/ /g' > new_chr22.E.Asia.clrout```

Thank you so much in advance!

3
  • 2
    Welcome, that's because you are using the g greedy command. Feb 22, 2021 at 21:12
  • Thank you for the fast feedback! What should I use instead of g?
    – kllrdr
    Feb 22, 2021 at 21:15
  • 1
    Nothing, without it, the substitutin will be performed in the first match only. Feb 22, 2021 at 21:16

1 Answer 1

1

From the comment seem's that you have resolved, however, here another couple of ways :

sed -E 's/(^[[:digit:]]+)\.[[:digit:]]+([[:space:]]+)/\1\2/g' file

Or awk:

awk '{ sub(/\.[[:digit:]]+/, " ", $1) }1' file
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .