Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How to remove the first dot before the first number?

For example

I have the following file

  more file


  Version …………2.465.76.8.332

I want to get only the version number - 2.465768.332

share|improve this question
3  
Your question title says delete first dot but sample output shows something else. Could you fix your question? –  devnull Mar 18 at 11:36
    
Also, what I never noticed, why do you remove the second and third dots from the version number? Is this a typo? –  Graeme Mar 18 at 11:43
    
Can we get confirmation on this Q whether we actually want to delete the leading dots or both the leading dots plus the 2nd and 3rd dots as well? –  slm Mar 18 at 15:50

3 Answers 3

up vote 3 down vote accepted

Assuming removing the dots from the version number is a typo.

sed can easily do the job:

echo 'Version …………2.465.76.8.332' | sed 's/^[^0-9]*//'

To extract only the version number from a file the number on is the first line beginning with 'Version' and nothing follows the version number, you could do:

sed -n '0,/^Version/ s/^Version[^0-9]*//p' file
share|improve this answer

Using sed you could say:

sed -n '/Version/{s/^[^0-9]*//;s/\([^.]*\.[^.]*\)\./\1/p}' filename

For your sample input, it'd produce:

2.46576.8.332

As mentioned in the comment, it isn't quite clear what is the desired output. If it's the expected output as mentioned in the question body, you might use awk in order to improve readability:

sed -n '/Version/{s/^[^0-9]*//p}' inputfile | awk -F. '{print $1,$2$3$4,$5}' OFS=.

which would produce:

2.465768.332
share|improve this answer
    
This will also process the numbers from any other line in the file that happens to contain the string 'Version' –  Graeme Mar 18 at 11:57
grep -oP 'Version.*?\K[\d.]+$' filename
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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