1

I've tried all solutions that I found, but nothing seems to work as it should.

I have a file with text data. I need to add some characters at the end of each line.

I've tried already:

awk '{print $0"XYZ"}' $newfilename-final.txt > $newfilename-XYZ.txt
perl -nle 'print $_, "XYZ"' $newfilename-final.txt > $newfilename-XYZ.txt
sed 's/$/XYZ/' $newfilename-final.txt > $newfilename-XYZ.txt

All of them added XYZ, but not at the end of every string, but in new lines between strings.

How to solve this issue?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116

2 Answers2

1

Testing your awk program, it works for me as intended. I suppose the problem is that your input file uses different newline sequences than the your OS default (probably the Windows-style "CR+LF" when you are on UNIX or Mac OS). If that's the case, this other post could be of help: How to convert DOS/Windows newline (CRLF) to Unix newline (\n) in a Bash script?.

Community
  • 1
  • 1
mkorvas
  • 563
  • 3
  • 10
0

if it is every line

sed 's/[^[:print:]]*$/[Here]&/' YourFile

you take care of every trailing non printable char before the insertion with the [^[:print:]]* and & in replacement pattern

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43