Crispy_Crafter
Crispy_Crafter

Reputation: 11

Carriage return via Bash awk

Another awkward problem

I needed the following code to not add a carriage return at the end of each line.

 awk -v coord_file="$txt_1"  '  
 NR <= '$region1' {print $0}
 NR > '$region1' && NR <= '$region2'{$6 = "" ; $7 = "" ; print $0}
 NR > '$region2' {print coord_file} 
 {CONVFMT="%.10f"} ' input.sh > tmp  

I found I needed to post process my file to remove carriage returns. All this is done in nested loops hence

 IN=tmp
 OUT=output"$[$i]$[$j]".sh
 cat  $IN | tr -d '\r' > $OUT
 rm $IN

Upvotes: 1

Views: 2223

Answers (1)

Amnon
Amnon

Reputation: 334

print adds a newline in awk. You can repress this by setting ORS (the Output Record Separator) to something else. Or you can use printf instead of print.

Upvotes: 1

Related Questions