Issue
I have a file:
Text1 text2 50
Text3 text4 60
I would like to make the following using sed command:
class="lang-none prettyprint-override">Text1 Text1 text2 50
Text3 Text3 text4 60
I need to copy the first string and add it to the line.
Solution
sed 's/[^ ]\+ /&&/' input-file
Assumes a space as separator, and not a tab. &
is shorthand for "entire match" when used on replacement side of s///
substitution
Note that prior answer s/.* /&&/
above only works for 2-word inputs. It's too greedy. So we're matching one or more non-space characters followed by a space.
Answered By - stevesliva Answer Checked By - Terry (WPSolving Volunteer)