0

Hi Trying to insert <br> at the end of command output with awk but it is printing at the beginning

My command and expected output: cat cmd.out |awk ' {printf $0"<br>\n" }' Getting addresses from network interface table...<br> Getting addresses from sitelist...<br>

But actual output is: <br>ing addresses from network interface table... <br>ing addresses from sitelist...

What am I doing wrong? Thanks

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • 4
    looks like your input file contains windows/dos line endings (`\r\n`); easy solution would be to run `dos2unix cmd.out` (removes `\r` from file so only have to run once after file is created/populated) before running your code; alternatives would be to use `tr -d '\r'`, or add code to your `awk` script to remove the `\r` characters – markp-fuso May 29 '23 at 23:49
  • 2
    This should help: `dos2unix \n" }'` – Cyrus May 30 '23 at 00:01
  • Never do `printf $0` (or $anything) as it'll fail when your input contains printf formatting characters like `%s`. Use `printf "%s
    \n", $0` instead of `printf $0"
    \n"`
    – Ed Morton May 30 '23 at 15:28

0 Answers0