osx - how to do simple concat in awk in mac -


so have file list.txt similar one:

                              186                               423                               423                               234                               634                               437 

and want output similar this:

set 186 0 set 423 0 set 423 0 set 234 0 set 634 0 set 437 0 

i tried this:

sed 's/^ *//g' list.txt | awk '{a="set ";b=" 0";print a,$0,b}' 

but prints

  0 186   0 423   0 423   0 234   0 634   0 437 

given that

sed 's/^ *//g' list.txt | awk '{a="set ";b=" 0";print a,$0}' 

works perfect:

set 186 set 423 set 423 set 234 set 634 set 437 

so don't know i'm doing wrong.

do know how solve , why print a,$0,b doesn't work?

it doesn't work because input file created on windows , has spurious control-ms @ end of each line , that's messing displayed output. run dos2unix on file or otherwise rid of control-ms , script work written, better way simply:

awk '{print "set",$1,0}' list.txt 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -