LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Delete spaces from text file (https://www.linuxquestions.org/questions/linux-newbie-8/delete-spaces-from-text-file-4175487864/)

ceantuco 12-13-2013 12:55 PM

Delete spaces from text file
 
Hi Guys,

I have a space delimited file that I would like to edit.

Basically, I need to delete 4 blank spaces.

See example:

Code:

888 8888 888888888/ABC          88 888888888888888  1195.00
 888 8888 888888888/ABC          88 888888888888888      1195.00

I want to remove 4 spaces from the second line so it would match the first line. I tried using the CUT command but I could not do it.

Thank you

ceantuco 12-13-2013 12:57 PM

The forum fixed the margin for me... I should copy and paste the entire file here hehehhe well, the second line has 1195.00 moved 4 spaces to the right.

Thank you!

TobiSGD 12-13-2013 12:58 PM

If you want to show us the original formatting in your posts please use code-tags (look at the link in my signature) to post it.

ceantuco 12-13-2013 01:12 PM

ok
Thank you!

[code]

800 8010 690041334/MOH 18 201015104280818 3195.00
800 8010 690041334/MOH 18 201015104280818 3195.00

Thank you

ceantuco 12-13-2013 01:14 PM

Ok

Thank you

Code:



 800 8010 690041334/MOH          18 201015104280818  3195.00
 800 8010 690041334/MOH          18 201015104280818      3195.00


Madhu Desai 12-13-2013 01:48 PM

Code:

$ cat file
 800 8010 690041334/MOH          18 201015104280818  3195.00
 800 8010 690041334/MOH          18 201015104280818      3195.00

Code:

$ sed 's/8 *3/8  3/g' file
 800 8010 690041334/MOH          18 201015104280818  3195.00
 800 8010 690041334/MOH          18 201015104280818  3195.00

Or, still better is
Code:

$ sed -e 's/^.//; s/  */ /g' file
800 8010 690041334/MOH 18 201015104280818 3195.00
800 8010 690041334/MOH 18 201015104280818 3195.00


colucix 12-13-2013 02:53 PM

Using awk version 4:
Code:

awk 'NR == 1 {
  n = split($0, c, FS, s)
}
{
  for (i = 0; ++i <= n;)
    printf "%s", c[i] s[i]
  print ""
}' file

This preserves the spaces of the first line and print the other lines accordingly.


All times are GMT -5. The time now is 03:02 AM.