Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wrong line breaks in output 1

Status
Not open for further replies.

timfissler

Programmer
Apr 8, 2015
2
DE
Hey there,

I want to use awk to automate code production for an SPSS-syntax. Therefore I have a text file ("sItems.txt") containing variable names that looks like this:

Code:
v_48, v_50, v_52, v_54, v_56, v_84, v_86, v_88, v_90, v_92, v_94, v_96, v_98, v_100, v_102, v_2be07, v_9decd, v_108, v_110, v_112, v_114, v_116, v_118, v_120, v_122

I want awk to print the following SPSS command for every variable name: "COMPUTE v_xx=(v_xx - 3) * (-1) + 3." where v_xx is the current variable name. I use the following syntax (on Mac OS X 10.10 if that is important):

Bash:
cat sItems.txt | awk 'BEGIN{RS=", "}{print "COMPUTE " $0 "=(" $0 " - 3) * (-1) + 3."}'

The resulting output looks like this:

Code:
COMPUTE v_48=(v_48 - 3) * (-1) + 3.
COMPUTE  v_50=( v_50 - 3) * (-1) + 3.
COMPUTE  v_52=( v_52 - 3) * (-1) + 3.
COMPUTE  v_54=( v_54 - 3) * (-1) + 3.
COMPUTE  v_56=( v_56 - 3) * (-1) + 3.
COMPUTE  v_84=( v_84 - 3) * (-1) + 3.
COMPUTE  v_86=( v_86 - 3) * (-1) + 3.
COMPUTE  v_88=( v_88 - 3) * (-1) + 3.
COMPUTE  v_90=( v_90 - 3) * (-1) + 3.
COMPUTE  v_92=( v_92 - 3) * (-1) + 3.
COMPUTE  v_94=( v_94 - 3) * (-1) + 3.
COMPUTE  v_96=( v_96 - 3) * (-1) + 3.
COMPUTE  v_98=( v_98 - 3) * (-1) + 3.
COMPUTE  v_100=( v_100 - 3) * (-1) + 3.
COMPUTE  v_102=( v_102 - 3) * (-1) + 3.
COMPUTE  v_2be07=( v_2be07 - 3) * (-1) + 3.
COMPUTE  v_9decd=( v_9decd - 3) * (-1) + 3.
COMPUTE  v_108=( v_108 - 3) * (-1) + 3.
COMPUTE  v_110=( v_110 - 3) * (-1) + 3.
COMPUTE  v_112=( v_112 - 3) * (-1) + 3.
COMPUTE  v_114=( v_114 - 3) * (-1) + 3.
COMPUTE  v_116=( v_116 - 3) * (-1) + 3.
COMPUTE  v_118=( v_118 - 3) * (-1) + 3.
COMPUTE  v_120=( v_120 - 3) * (-1) + 3.
COMPUTE  v_122
=( v_122
 - 3) * (-1) + 3.

So you see that everything is fine except the last line of the output that contains two wrong line breaks. It also happened to me earlier with other awk scripts that awk messed up the last line in a similar way.

Do you have any suggestions that would help solving this issue?

Best,
Tim
 
What about this ?
Code:
tr -d '\r\n' <sItems.txt | awk 'BEGIN{RS=", "}{print "COMPUTE " $0 "=(" $0 " - 3) * (-1) + 3."}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top