So I want to do something like this in Perl:if (/number=[0-9]*;/){ print $&$`$';}Is this possible in sed? That is, I want to isolate a part of a line and move it from the middle to the front.
sed: moving elements in a line around
sed;perl
sed 's/\(.*\)\(number=[0-9]*;\)/\2\1/'However, if there were several occurrences of number[0-9]*;, that would move the last one (because of the greedy .*). To move the first one:sed -ne 's/number=[0-9]*;/\&\/; s/\(.*\)\n\(.*\)\n/\2\1/p'That is, not use .*, but wrap the (first this time) occurrence of the pattern inside newline characters (the only character that cannot otherwise occur in the pattern space), which makes the match uniquely identifiable my the next s command.That assumes the input is valid text (in particular that there are no sequences of bytes that don't form valid characters).You can also use perl on the command line like with: perl -pe 'if (/number=[0-9]*;/) {$_ = $&$`$'}'Or perl -pe 's/(.*?)(number=[0-9])/$2$1/'