2

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)

 34.34.55.4

after sed manipulation will be

 34.34 55.4
3
  • 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, 2012 at 7:52
  • 1
    @Zoredache although I usually recommend awk as well, its not so painful in sed ;)
    – SiegeX
    Feb 16, 2012 at 7:53
  • ok I update the question
    – Eytan
    Feb 16, 2012 at 7:57

3 Answers 3

3
echo -e '1.2.3.4\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 ;-)

2
$ sed 's/\./ /2' <<<'34.34.55.4'
34.34 55.4
2
  • this syntax not work on solaris
    – Eytan
    Feb 16, 2012 at 9:40
  • @Eytan the <<<'34.34.55.4' 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, 2012 at 16:53
2

Using GNU Awk:

Command:

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

Output:

34.34 55.4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .