please advice how to remove only the second "." character from the version number with awk

I need to fit the syntax for Linux & Solaris

I write the

  sed "s'/\./ /g'" - 

but this syntax remove all "." from the version number

for example (version number before)

after sed manipulation will be

 34.34 55.4
  • Have you considered awk instead? Doing this with SED is going to be painful simply because it has a very limited ability to deal with any kind of state. – Zoredache Feb 16 '12 at 7:52
  • 1
    @Zoredache although I usually recommend awk as well, its not so painful in sed ;) – SiegeX Feb 16 '12 at 7:53
  • ok I update the question – Eytan Feb 16 '12 at 7:57
echo -e '\n2.3.4\n5.6.7.8' | sed 's/\([^.]*\.[^.]*\)\./\1 /'

The part in braces will match "something without dot, a dot, something without dot". \1 in the replacement text will then refer to this submatch.

However, the other solution given is arguably far more elegant ;-)

$ sed 's/\./ /2' <<<''
34.34 55.4
  • this syntax not work on solaris – Eytan Feb 16 '12 at 9:40
  • @Eytan the <<<'' part was just an example for input. Simply replace it with a file name, or pipe something to it with echo. The sed command will certainly work. – SiegeX Feb 16 '12 at 16:53

Using GNU Awk:


awk '$0 = gensub( /\./, " ", 2 )' <<<""


34.34 55.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.