awk printing: strange result

Dear all,

I am using awk in a bash script to extract a list of x y z coordinates from a file such as:

%BEGIN 3D-SPACE COORDINATES
0.2085627338147950 0.2471306816410478 0.2085627338147950
0.1242549179185660 0.2755539793525220 0.4147884486606120
0.2030669560265720 0.3983372756773921 0.4596781191013200
0.7067131708643269 0.3305772813679979 0.4725877506177361
0.2145984149333280 0.3226923154644570 0.4418263501706269
0.6311637442761178 0.3184506694177131 0.4399444001080688
%END 3D-SPACE COORDINATES

my awk comand is:
awk '/%BEGIN 3D-SPACE COORDINATES/,/%END 3D-SPACE COORDINATES/' $name.geom | awk '{print" "$1" "$2" "$3" "}' | awk '!/COORDINATES/' > temp1

What I get is:

0.2308162774655759 0.1480521440577194 0.5021283247946412^M
0.1511096424690066 0.1233060439441793 0.4500675923279874^M
0.2023251655747262 0.2714463932173767 0.4821937835506821^M
0.4354815336547525 0.2936641560636020 0.4621607016307354^M
0.2240460471092144 0.2045465724198916 0.4711570022223424^M
0.3374757152666932 0.2634647746292220 0.4370902435765608^M
0.5903967673979990 0.4016591662102160 0.3766061929875720^M
0.6632378213716280 0.6461468540777490 0.3725764025724530^M
0.3531727567629250 0.3667579928368630 0.3740439462339640^M

As can be seen there is a "^M" at the end of the z coordinate.

My question is:
has anyone met such a problem before, and how may it be avoided.

Any help would be very welcome.

Thank you very much!!

Pauli.

The given input and output don't have any relationship with each other, post the output of the given input file and desired output.

Regards

Hi Frankin52,

I am extracting a data block, exactly as below, from a large file.

%BEGIN 3D-SPACE COORDINATES
0.2085627338147950 0.2471306816410478 0.2085627338147950
0.1242549179185660 0.2755539793525220 0.4147884486606120
0.2030669560265720 0.3983372756773921 0.4596781191013200
0.7067131708643269 0.3305772813679979 0.4725877506177361
0.2145984149333280 0.3226923154644570 0.4418263501706269
0.6311637442761178 0.3184506694177131 0.4399444001080688
%END 3D-SPACE COORDINATES

What I need to get is as follows:

0.2085627338147950 0.2471306816410478 0.2085627338147950
0.1242549179185660 0.2755539793525220 0.4147884486606120
0.2030669560265720 0.3983372756773921 0.4596781191013200
0.7067131708643269 0.3305772813679979 0.4725877506177361
0.2145984149333280 0.3226923154644570 0.4418263501706269
0.6311637442761178 0.3184506694177131 0.4399444001080688

However I get this �^M� at the end of the z coordinate:

0.2085627338147950 0.2471306816410478 0.2085627338147950^M
0.1242549179185660 0.2755539793525220 0.4147884486606120^M
0.2030669560265720 0.3983372756773921 0.4596781191013200^M
0.7067131708643269 0.3305772813679979 0.4725877506177361^M
0.2145984149333280 0.3226923154644570 0.4418263501706269^M
0.6311637442761178 0.3184506694177131 0.4399444001080688^M

The awk command that I am using is:

awk '/%BEGIN 3D-SPACE COORDINATES/,/%END 3D-SPACE COORDINATES/' input | awk '{print" "$1" "$2" "$3" "}' | awk '!/COORDINATES/' > output

I would be grateful for any assistance on this.

Thanks again,

Pauli.

With your command I get the desired output however, it's needless to use awk twice, this command should be sufficient:

awk '/%BEGIN 3D-SPACE COORDINATES/,/%END 3D-SPACE COORDINATES/ {if(!/COORDINATES/){print $1,$2,$3}}' 

Have you transfer the file from a windows environment?

Hi Frankin52,

Thanks for your reply and your tip on awk. The files which I am extracting data from are created by windows softwear. And I am using WinSCP to transfer them to my Linux account in binary mode.

Pauli

Use this command to convert the dos/windows file to a unix format:

 tr -d '\r' < dosfile > unixfile

Regards

Hi Frankin52,

Thanks for your help on this issue. That seems to have done the trick!!

No more crazy "^M"

Cheers,

:b: