From: doug <do...@o2...> - 2011-06-11 10:10:59
|
On 11/06/11 00:50, Nick Hall wrote: > <snip> >> >> >> from Nick: >> >> <quote> >> :1,$s/^\([a-zA-Z]*,[a-zA-Z]*,\)/\1,,,/ >> or >> :1,$s/[a-zA-Z]*,[a-zA-Z]*,/&,,,/ >> >> <endquote> >> >> These worked fine in vim. >> >> But in kate however they didn't work for some reason. Maybe >> I've not understood the construction properly. >> >> Using Search: ^\([a-zA-Z]*,[a-zA-Z]*,\) and Replace: \1,,, >> nothing happened > > In vi, the colon introduces the command (s=substitute), the 1,$ is a > range of lines ($=last line in file). > > In kate, the "(" and ")" don't need to be escaped and doing so seems to > cause a problem. > >> Using Search: [a-zA-Z]*,[a-zA-Z]*, and Replace:&,,, >> the first two columns were replaced by "&" (no quotes) > > In vi, the "&" will be replaced by the contents of matched string. > Perhaps a different character is used in kate? If not, you will have to > use groupings and \1 \2 etc... , but this isn't a problem. > > Nick. Nick, again many thanks. I'm familiar with the colon and range in vim and just about on nodding acquaintance with sed (but never used it). As far as kate is concerned, it was the \( and \) causing trouble with my version of kate in Search: ^\([a-zA-Z]*,[a-zA-Z]*,\) and Replace: \1,,, Once I'd removed the escaping it worked as expected. However your other option Search: [a-zA-Z]*,[a-zA-Z]*, and Replace:&,,, doesn't work. The [a-zA-Z]*,[a-zA-Z]*, seems not to be grouped by kate, so \1,,, instead of &,,, just substitutes for the first two columns. I'm grateful for your perseverance: it's helping me to understand better and to notice quirks in different editors that can trip me up. Doug |