Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share
    
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

3 Answers 3

up vote 3 down vote accepted
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 ;-)

share
$ sed 's/\./ /2' <<<'34.34.55.4'
34.34 55.4
share
    
this syntax not work on solaris –  Eytan Feb 16 '12 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 '12 at 16:53

Using GNU Awk:

Command:

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

Output:

34.34 55.4
share

This site is currently not accepting new answers.

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