I’m trying to replace;
randomtext{{XX icon}}
by
randomtext{{ref-XX}}
..in a file, where XX could be any sequence of 2 or 3 lowercase letters.
I attempted rearranging the word order with awk before replacing “icon” with “ref-” with sed;
awk '{print $2, $1}'
..but since there is no space before the first word nor after the second one, it messed up the curly brackets;
icon}} {{XX
What is the simplest way to achieve this using sed?
This one liner uses the substitute command
s/PATTERN/REPLACE/.{{matches two brackets.\([a-z]\{2,3\}\)captures the pattern that matches 2 or 3 lowercase letters.\smatches a white space.iconmatches the literal string “icon”. Then we replace the match, that is,{{....iconwith the literal string{{ref-and the captured 2 or 3 letter word.