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

How to append a suffix

How to append a suffix

(OP)
Hi Guys.

I have a huge file with the following format:

__415068.737_2034568.082____2488.000255___0___0__1_2ALMEJA_FN1+90_LML__________________UNKNOWN_____________LGC__TIME
__415113.412_2034444.670____2596.000255___0___0__1_2ALMEJA_FN1+90_LML__________________UNKNOWN_____________LGC__TIME
__415134.685_2034385.902____2636.000255___0___0__1_3ALMEJA_FN1+90_LML__________________UNKNOWN_____________LGC__TIME
__417259.277_2036924.200____3412.000132__33_191____1MZTN_SAL_PRES______________________UNKNOWN_____________LGC__TIME
__417178.007_2036820.533____3328.000132__33_191____2MZTN_SAL_PRES______________________UNKNOWN_____________LGC__TIME

NOTE: Undescores ( _ ) are in fact blanks ( whitespaces ).


My desired output:
__415068.737_2034568.082____2488.000255___0___0__1_2ALMEJA_FN1+90_LMLv_v2_______________UNKNOWN_____________LGC__TIME
__415113.412_2034444.670____2596.000255___0___0__1_2ALMEJA_FN1+90_LML_v2________________UNKNOWN_____________LGC__TIME
__415134.685_2034385.902____2636.000255___0___0__1_3ALMEJA_FN1+90_LML_v2________________UNKNOWN_____________LGC__TIME
__417259.277_2036924.200____3412.000132__33_191____1MZTN_SAL_PRES_v2____________________UNKNOWN_____________LGC__TIME
__417178.007_2036820.533____3328.000132__33_191____2MZTN_SAL_PRES_v2____________________UNKNOWN_____________LGC__TIME

I need to append a "_v2" suffix to this column_____________^^^^^^^^^^^^^^^^^^^^^^

As you can see, there are some times that the column is #7, but some other times it is #6, so its not easy for me to use awk in this case.

I need to keep spacing in the output.

I also tried sed, but don't know how the specify the position of the string I want to add the suffix to.



Thank you very much for your help guys. I come here when spent a lot of time trying to solve the problem with no success.

RE: How to append a suffix

If _ is a space then LML is in column 9 and PRES in column 8
I assume the _ in 2ALMEJA_FN1+90_LML is not a space i.e.

CODE

#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+---10----+---11----+---12----+---13-
  415068.737 2034568.082    2488.000255   0   0  1 2ALMEJA_FN1+90_LML                  UNKNOWN             LGC  TIME
  415113.412 2034444.670    2596.000255   0   0  1 2ALMEJA_FN1+90_LML                  UNKNOWN             LGC  TIME
  415134.685 2034385.902    2636.000255   0   0  1 3ALMEJA_FN1+90_LML                  UNKNOWN             LGC  TIME
  417259.277 2036924.200    3412.000132  33 191    1MZTN_SAL_PRES                      UNKNOWN             LGC  TIME
  417178.007 2036820.533    3328.000132  33 191    2MZTN_SAL_PRES                      UNKNOWN             LGC  TIME
#---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+---10----+---11----+---12----+---13- 
Try:

CODE

awk '{x=substr($0,52,35);gsub(" ","",x);printf "%1s%-35s%1s\n",substr($0,1,51),substr(x "_v2",1,35),substr($0,87)}' TheFile 

RE: How to append a suffix

CODE

sed 's/\([A-Z]\)\(   \)/\1_v2/1' TheFile 

RE: How to append a suffix

(OP)
Hello PDreyer, your assumption was right.

Sorry, I was a little bit tired yesterday, didn't notice that.

Your script works perfect. Its impressive what awk and sed can do, of course knowing how to use them smile.


Thank you very much for your time.

You helped me a lot.


Regards,

Raul.

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