Hi!
I have a strange behaviour from sed and awk, but I'm not sure, if I'm doing something wrong:
I have a list of words, where I want to add the following string at the end of each line:
\;\;\;\;0\;1
I try like this:
$ cat myfile | awk '{if ( $0 != "" ) print $0"\;\;\;\;0\;1"}'
Result: (it overwrites text at the beginning of the line)
;;;;0;1y
;;;;0;1hand
;;;;0;1occasion of
;;;;0;1other hand
;;;;0;1e
;;;;0;1ion
Same with sed ...
Am I doing something wrong? I use bash on Ubuntu 11.04.
Thanks for your help.
Regis
See if this works for you:
sed 's#$#\\;\\;\\;\\;0\\;1#' File
nawk 'NF{$0=$0 ";;;;0;1"}1' myFile
OR
sed '/..*/s#.*#&;;;;0;1#' myFile
Thank you, for you replies. I learned a few things, but - it didn't help: still the same effect.
I tried with
$ cat myfile | while read line ; do echo ${line}';;;;0;1' ; done
and even installed a different shell (ksh instead of bash) ... same effect.
I'll go to the office, and try on a different machine.
If you are on Unix, ensure that your file does not have Windows end-of-line characters. The output of the command:
od -bc myfile
should not show any "\r" characters.
Try fixing the end-of-line character (as shown below) before running your awk script on the file.
dos2unix myfile
It must be a problem with my Ubuntu-installation at home:
I tried in the office on a Redhat system: works as expected, no problem!
$ od -bc myfile does NOT show any \r in the output.
However, I'll give a try with dos2unix when I'm back at home.
Thank you for your help! I appreciate to learn from all these answers!
---------- Post updated at 06:10 PM ---------- Previous update was at 09:50 AM ----------
On the office-Linux (Redhat), od -bc didn't show any \r ,
but at home, there where a lot of this characters.
$ dos2unix resolved this problem.
Thank you very much!
Kind regards - Regis