[Solved] Howto remove extra space in the file

Hi Gurus,

I have a file which contains some special char or space.
when using cat -evt I can see the file as following:

0,"0000","abc/def aaa                                                                                                                              ","01/01/1900","12/31/2299",1001,"abc"$
1,"0001","abc > 1cde                                                                                               ","01/01/1900","06/30/2013",1001,"abc"$
0,"0000","abc/def aaa ","01/01/1900","12/31/2299",1001,"abc"$ 

should be in one line,but it appears as two lines without any line feeder. the strange thing is I copied this from vi editor, I can not move it to one line using backspace key.

anybody has some idea how to remove these extra space in unix.
after posting I found the file became one line with big space. when I copied it from vi editor to notepad, it appears as two line.

I print a screeshot, but I dont know how to attached it, can anybody tell me how can i attach a screenshot.

Thanks in advance.

Well, it's already in one line, isn't it? Or am I missing something?

From your pasted input it definitely seems that there are several blank characters in the third field.

The line may be so wide that it's not fitting your screen and it apparently breaks into two lines, even though it's only one.

Using awk

awk '{$1=$1}1' file
3 Likes

very clever :b:

This works perfectly, would you please briefly explain this for me since I don't have that much unix experience.

Thanks

This is a very commonly used solution. It reconstruct every field setting default one space as filed separator.
{$1=$1} reconstruct
1 print every line

1 Like

Thanks for your explanation.

:b: