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

Replace WORD by Position

Replace WORD by Position

(OP)
Hi Guys,

I Need some help Here please.

I have a large file like this:
437493.562 2041538.750 4104.000 0 0 195 1 2FE_04_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
437493.562 2042413.750 3660.000 0 0 195 1 2FE_04_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
437493.562 2043313.750 3048.000 0 0 195 1 2FE_04_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
437493.562 2043963.750 2364.000 0 0 195 1 3FE_04_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2048738.875 1320.000255 230 0 1 1FE_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2047538.875 1740.000255 230 0 1 2FE_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2046438.875 2052.000255 230 0 1 2FE_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2045213.750 2364.000255 230 0 1 2FE_STALKU_JJHP UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms

I need to add a suffix to the Word between characters 52 to 102 of every line. For example, for line 1 I need to replace FE_04_STALKU_JJHP for FE_04_STALKU_JJHP_MODIF while keeping spacing.

So, my desired output would be:
437493.562 2041538.750 4104.000 0 0 195 1 2FE_04_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
437493.562 2042413.750 3660.000 0 0 195 1 2FE_04_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
437493.562 2043313.750 3048.000 0 0 195 1 2FE_04_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
437493.562 2043963.750 2364.000 0 0 195 1 3FE_04_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2048738.875 1320.000255 230 0 1 1FE_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2047538.875 1740.000255 230 0 1 2FE_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2046438.875 2052.000255 230 0 1 2FE_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
398743.438 2045213.750 2364.000255 230 0 1 2FE_STALKU_JJHP_MODIF UNKNOWN JHP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms

The Problem here is that columns 3 and 4 get together sometimes as you can see in row 5. So, I'm not sure if it's better to try SED, maybe something like:

sed -rni 's/^(.{52})(.* )(.*)/\1\2_MODIF \3/gp' file ( not working ).


Thanks a lot in advance.

RE: Replace WORD by Position

Why not simply replace "_STALKU_JJHP" with "_STALKU_JJHP_MODIF" ?

RE: Replace WORD by Position

Wit sed works it too:

CODE

$ sed -r 's/_STALKU_JJHP/_STALKU_JJHP_MODIF/g' rulmorf.txt > rulmorf_out.txt 
or

CODE

$ sed -r 's/(_STALKU_JJHP)/\1_MODIF/g' rulmorf.txt > rulmorf_out.txt 

RE: Replace WORD by Position

(OP)
Hello Mikrom, thank you very much for your help.

The Problem is that the word changes. For example, at the beginning of the file it is FE_04_STALKU_JJHP, then it changes to FE_STALKU_JJHP and
it continues to change as you go down in the file.

Thanks again

RE: Replace WORD by Position

(OP)
Almost PHV, thanks a lot.

Now the only Problem is that it displaces the last five columns 6 positions to the right and I need to preserve the position:

394993.438 2022063.750 3612.000255 0 0 1 1FN_23_STALKU_CEGG UNKNOWN EMP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
394993.438 2022776.250 3604.000255 0 0 1 2FN_23_STALKU_CEGG UNKNOWN EMP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
394993.438 2023651.250 3460.000255 0 0 1 2FN_23_STALKU_CEGG UNKNOWN EMP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms

394993.438 2022063.750 3612.000255 0 0 1 1FN_23_STALKU_CEGG_MODIF UNKNOWN EMP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
394993.438 2022776.250 3604.000255 0 0 1 2FN_23_STALKU_CEGG_MODIF UNKNOWN EMP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms
394993.438 2023651.250 3460.000255 0 0 1 2FN_23_STALKU_CEGG_MODIF UNKNOWN EMP TIME Mega_Union_Lit_de_Tabasco_Marino_2012 meters ms

You can't see it but there are 32 blanks between the words FN_23_STALKU_CEGG and UNKNOWN. When I run your SED script I still have 32 blanks between FN_23_STALKU_CEGG_MODIF and UNKNOWN and I need to have
26 blanks ( which is 32-6 <-- The width of the word _MODIF )

Thank you very much

RE: Replace WORD by Position

(OP)
That's It Man.

Thank you very much.

You guys are really good with AWK and SED.

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