1

I am trying to put a char at the end of each line in a file:

a
aa
aaa
aah
aahed
aahing
aahs
aal
aalii
aaliis

using sed/awk:

awk '{print  $0 "A"}' words_alpha.txt > words_alpha_hyp.txt
sed -i 's/$/A/' words_alpha.txt > words_alpha_hyp.txt 

I got always instead the char 'a' a prefix:

 A
 A
 Aa
 Ah
 Ahed
 Ahing
 Ahs
 Al
 Alii
 Aliis
 Als
 Am
 Ani
 Ardvark
 Ardvarks

Interestingly if I try to '\n' before the char 'a':

awk '{print $0 "\n a"}' words_alpha.txt > words_alpha_hyp.txt

a
 a
aa
 a
aaa
 a
aah
 a
aahed
 a
aahing
 a
aahs
 a
aal
 a

I does what it supposed to do... I don't understand it...

Inian
  • 80,270
  • 14
  • 142
  • 161
asasa178
  • 221
  • 1
  • 11
  • Please add sample input (no descriptions, no images, no links) and your desired output for that sample input to your question (no comment). – Cyrus Mar 06 '20 at 20:41

1 Answers1

1

Your input file most likely has DOS CRLF line terminators i.e. instead of \n being a \r\n. Modify your record separator to handle those lines, needs GNU awk for having to use a multi character record separator

awk -v RS="\r\n" '{ $0 = $0 "a" }1' file

Or make the obvious choice of converting the file to *nix line endings \n by doing dos2unix file and run your original command again.

Inian
  • 80,270
  • 14
  • 142
  • 161