danilo
danilo

Reputation: 21

remove space from specific column by bash

I am new of bash command and I really appreciate your help.

I have a file like this

ATOM      1  N   LYS P1852      10.932   0.523 -24.701  1.00  0.00
ATOM      2  HN1 LYS P1852      11.571   0.864 -25.419  1.00  0.00
ATOM      3  HN2 LYS P1852      10.431   1.305 -24.278  1.00  0.00
ATOM      4  HN3 LYS P1852      10.154   0.023 -25.132  1.00  0.00
ATOM      5  CA  LYS P1852      11.556  -0.319 -23.640  1.00  0.00

and I need to remove space from specific position (position 30 let say) for all the lines. The output has to be as follow:

ATOM      1  N   LYS P1852     10.932   0.523 -24.701  1.00  0.00
ATOM      2  HN1 LYS P1852     11.571   0.864 -25.419  1.00  0.00
ATOM      3  HN2 LYS P1852     10.431   1.305 -24.278  1.00  0.00
ATOM      4  HN3 LYS P1852     10.154   0.023 -25.132  1.00  0.00
ATOM      5  CA  LYS P1852     11.556  -0.319 -23.640  1.00  0.00

I was trying sed and other commands but no solution until now has worked.

Thanks you

Upvotes: 0

Views: 56

Answers (1)

Gyuri16
Gyuri16

Reputation: 143

You can use cut:

cut --complement -c 30 input.txt

From the manual:

   -c, --characters=LIST
          select only these characters
   --complement
          complement the set of selected bytes, characters or fields

--complement is GNU cut specific, if that is not available:

cut -c -29,31- input.txt

Above commands remove any character at position 30. If you only want to remove space:

sed -E 's/^(.{29}) /\1/' input.txt

Upvotes: 1

Related Questions