Cut a file delimited on a number with one or more digits

awkcutperlregular expressionsed

I'm looking for a way to extract the first column of a text file that has no specific delimiters except for arbitrary digits that begin the next column. Example:

John Smith 1234 Main Street
Amy Brown and Sally Williams 9 Drury Lane
Sunny's 1000 Brown Avenue

Expected output would be:

John Smith
Amy Brown and Sally Williams
Sunny's

It appears that cut doesn't support functionality such as cut file.txt -d {0..9} -f 1

Solutions can use any standard unix utility.

Best Answer

$ awk -F'[0-9]' '{ print $1 }' file
John Smith
Amy Brown and Sally Williams
Sunny's

With -F'[0-9]' we say that digits are to be considered field separators in the input data, and with print $1 we output the first digit-separated field.

Change -F'[0-9]' to -F' *[0-9]' to also get rid of any spaces before the digit.

Related Question