awk/sed + replace only the second char with one space

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

Eytan

Posted 2012-02-16T07:50:13.787

Reputation: 47

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 – 2012-02-16T07:52:01.087

1@Zoredache although I usually recommend awk as well, its not so painful in sed ;) – SiegeX – 2012-02-16T07:53:30.200

ok I update the question – Eytan – 2012-02-16T07:57:37.303

Answers

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 ;-)

jakob

Posted 2012-02-16T07:50:13.787

Reputation: 66

2

$ sed 's/\./ /2' <<<'34.34.55.4'
34.34 55.4

SiegeX

Posted 2012-02-16T07:50:13.787

Reputation: 1 911

this syntax not work on solaris – Eytan – 2012-02-16T09:40:16.023

@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 – 2012-02-16T16:53:36.527

2

Using GNU Awk:

Command:

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

Output:

34.34 55.4

Birei

Posted 2012-02-16T07:50:13.787

Reputation: 2 744