INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Wrong line breaks in output

Wrong line breaks in output

(OP)
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):

CODE --> 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

RE: Wrong line breaks in output

(OP)
Thanks PHV that solved the issue :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close