Answer the question
In order to leave comments, you need to log in
How to find a word in a string and move or copy it to the beginning of the string?
We have Linux, a file with lines. It is necessary to copy or move the digital part separated by dots to the beginning of the line.
bla bla 23.33.72 bla
bla bla la na 45.34.33 bla en
bla la na 45.34.33 bla urjt To
be received
23.33.72 bla bla 23.33.72 bla
45.34.33 bla bla la na 45.34.33 bla en
41.65.32 bla la na 45.34.33 bla urjt
Answer the question
In order to leave comments, you need to log in
You can find numbers like this: [\d.]*
then you grab it with parentheses and add it as you like: by concatenation, replacement, or something else.
for example like this:s/.*?([\d.]+).*/$1 $&/
[[email protected] ~]$ text="\
> bla bla 23.33.72 bla
> bla bla la na 45.34.33 bla en
> bla la na 45.34.33 bla urjt
> "
[[email protected] ~]$
[[email protected] ~]$ echo -n "$text"
bla bla 23.33.72 bla
bla bla la na 45.34.33 bla en
bla la na 45.34.33 bla urjt
[[email protected] ~]$
[[email protected] ~]$ echo -n "$text" | sed 's/.* \([0-9]*\.[0-9]*\.[0-9]*\) .*/\1 &/'
23.33.72 bla bla 23.33.72 bla
45.34.33 bla bla la na 45.34.33 bla en
45.34.33 bla la na 45.34.33 bla urjt
[[email protected] ~]$
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question