Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following line in a file:

      Linux Release............5.4.2.0-02 12_12_2011_07:31:23

How do I remove all characters before the first number with sed or awk?

I wish to get the following result:

      5.4.2.0-02 12_12_2011_07:31:23
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Try this:

sed -e 's/[^0-9]\+//'
share|improve this answer
    
what I need to change in the syntax in order to run it also on SOLARIS? –  Eytan Jan 10 '12 at 12:18
    
I don't think redirection works that way. Try echo " InSight Release............4.3.7.1-02.4 February-20,-2011-9:56:19" | sed 's/[^0-9]\+//', it works for me. –  MadHatter Jan 10 '12 at 13:44
1  
@Eytan: You want it to work on Solaris, but you tagged your question "Linux". Do you need it to work on both? –  Dennis Williamson Jan 10 '12 at 16:54
    
@MadHatter: Did you mean for your comment to be attached to Birei's answer? If so, the <<< is for a Bash here-string. Other shells may not support it. –  Dennis Williamson Jan 10 '12 at 16:56
    
Denis, yes, I did, and thanks for that - one learns something every day! –  MadHatter Jan 10 '12 at 17:02
add comment

One way using sed:

sed 's/^[^0-9]*//' <<<"      Linux Release............5.4.2.0-02 12_12_2011_07:31:23"

Result:

5.4.2.0-02 12_12_2011_07:31:23
share|improve this answer
add comment

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.