Skip to main content

Timeline for replace text after match

Current License: CC BY-SA 3.0

16 events
when toggle format what by license comment
Nov 6, 2013 at 18:39 comment added Joseph R. @RanaKhan Or just modify the awk solution to awk '(R|S)D \\$/{...
Nov 6, 2013 at 18:38 vote accept Rana Khan
Nov 6, 2013 at 18:35 comment added terdon @RanaKhan please post another question with followup issues. It is hard to understand what you mean from the comments.
Nov 6, 2013 at 18:32 comment added Rana Khan @JosephR.@terdon when i pipe awk solution to another file and then trying to repeat the command for another match for example if line ends with "SD \" , replace -th with -to. it does that job however it revert back the previous " RD \" change. Dont know if i am missing anything. Can i do like if " line ends with RD \ or SD \ , replace -th with -to?
Nov 6, 2013 at 18:20 comment added terdon @JosephR. oh, so I didn't, huh could have sworn I had. I had a $ in there at some point but maybe only when testing.
Nov 6, 2013 at 18:19 comment added Joseph R. @terdon Actually, it's the other way around: trailing whitespace would trip the awk solution but not the sed or perl ones because you didn't anchor your pattern from the right.
Nov 6, 2013 at 18:17 comment added terdon @RanaKhan if the updated sed and perl solutions don't work, you probably have whitespace after the last \ .
Nov 6, 2013 at 18:15 comment added Joseph R. @RanaKhan ...and the updated sed and perl ones don't? Also, please don't forget to mark a satisfactory answer as accepted! Upvoting and accepting is the way to say thanks on Stack Exchange.
Nov 6, 2013 at 18:14 comment added Rana Khan @JosephR.@terdon: awk solution works just fine. thanks a lot.
Nov 6, 2013 at 18:09 comment added terdon @RanaKhan see edited answer.
Nov 6, 2013 at 18:08 comment added terdon @JosephR. thanks, I had actually corrected that in the version I tested and forgot to update my answer :).
Nov 6, 2013 at 18:07 comment added Joseph R. @terdon Actually, I think it's because there's a space between RD and '\' (so your awk solution should work).
Nov 6, 2013 at 18:04 comment added terdon @RanaKhan do you have trailing spaces after the \ at the end of the lines? Also, these solutions will not change the original file, you will need to redirect the output (sed 's/^-th\(.*RD\\\)/-to\1/' foo.txt > bar.txt) or use the -i flag with perl or sed: sed -i 's/^-th\(.*RD\\\)/-to\1/' foo.txt
Nov 6, 2013 at 18:04 history edited terdon CC BY-SA 3.0
added 559 characters in body
Nov 6, 2013 at 18:02 comment added Rana Khan didn't work:( it doent do anything, doesnt change anything
Nov 6, 2013 at 17:57 history answered terdon CC BY-SA 3.0