Reputation: 9363
I've run into very strange behavior in awk.
The input file is the following:
ABCD Yes
EFGH Yes
My awk script is the following:
/^ / {
print "ss", $2, "dd\n"
}
What I'm expecting is the following:
ss Yes dd
ss Yes dd
But, suprisingly, the result is the following:
ddYes
ddYes
Where is my "ss" and how come Yes attached in the back of "dd"?
Upvotes: 2
Views: 94
Reputation: 27
awk '{print "ss", $2, "dd\n"}' f2
f2
is input file and its working fine for me
Upvotes: -1
Reputation: 80921
The input file has DOS newlines. The \r
character at the end of each line is getting output as part of $2
and resetting the insertion point to the start of the line at which point the space from ,
and dd
are then printed out overwriting the initial ss
. (You can modify either the ss
prefix or the dd
suffix length to see this more clearly.)
Strip those from the original file and this will go away.
Upvotes: 3