Contact US

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.

Students Click Here

How to append a suffix

How to append a suffix

How to append a suffix

Hi Guys.

I have a huge file with the following format:


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

My desired output:

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.


  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


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


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

RE: How to append a suffix

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.



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! Already a Member? Login

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