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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to append a suffix 1

Status
Not open for further replies.

RulMorf

Technical User
Jul 19, 2013
14
MX
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.
 
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
 
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 :).


Thank you very much for your time.

You helped me a lot.


Regards,

Raul.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top