Skip to content
Advertisement

grep string after first occurrence of numbers

How do I get a string after the first occurrence of a number?

For example, I have a file with multiple lines:

JavaScript

I want to get the following output:

JavaScript

Thank you.

Advertisement

Answer

Imagine the following two input files :

JavaScript

A quick solution with awk would be :

JavaScript

This line substitutes the first string of anything that does not contain a number followed by a number by an empty set (""). This way $0 is redefined and you can reprint the first field or the remainder of the field. This line gives exactly the following output.

JavaScript

If you are interested in the remainder of the line

JavaScript

This will have as an output :

JavaScript

Be aware that an extra " *" is needed in the regular expression to remove all trailing spaces after the number. Without it you would get

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement