3

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

2 Answers 2

2

Try this:

sed -e 's/[^0-9]\+//'
5
  • what I need to change in the syntax in order to run it also on SOLARIS?
    – Eytan
    Jan 10, 2012 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, 2012 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? Jan 10, 2012 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. Jan 10, 2012 at 16:56
  • Denis, yes, I did, and thanks for that - one learns something every day!
    – MadHatter
    Jan 10, 2012 at 17:02
1

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

You must log in to answer this question.

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