Why awk printing wrong string into the output file?

0

I'm trying to read file with awk and write the output in a new file. Content file sample:

DATE_Login|09:01:20.507|2015-08-13|TIME_Session|00:32:32|MX|w32
DATE_Login|09:01:20.507|2015-08-13|TIME_Session|02:12:21|EU|osx
DATE_Login|09:01:20.507|2015-08-13|TIME_Session|01:15:04|SP|mobile

This is the command line

awk -F "|" 'NR > 4 {print $1 >> "/result.txt" } {if (NR > 15) exit 0}' /SSXCIPSOUR.txt**

But the content file output is:

^@2^@0^@1^@5^@-^@0^@8^@-^@1^@3^@ ^@0^@9^@:^@0^@1^@:^@2^@0^@.^@5^@0^@7^@
^@2^@0^@1^@5^@-^@0^@8^@-^@1^@3^@ ^@0^@9^@:^@0^@1^@:^@2^@0^@.^@5^@0^@7^@
^@2^@0^@1^@5^@-^@0^@8^@-^@1^@3^@ ^@0^@9^@:^@0^@1^@:^@2^@0^@.^@5^@0^@7^@

Maximo

Posted 2015-08-14T17:29:55.507

Reputation: 1

Answers

2

Your file is probably in some utf-16 encoding. Run the file command on the file to find out. If it comes from microsoft it is probably utf-16 little-endian. You could then convert it to utf-8 which is easier to awk with by doing on the file:

iconv -f UTF-16LE -t UTF-8 

meuh

Posted 2015-08-14T17:29:55.507

Reputation: 4 273