awk - find number in string

I am trying to go through a file that has a few million lines. I want to only pull lines that contain a number anywhere in the ninth field, but it has to be after a "/" character. Here is my awk:

awk -F\| '$9 ~ /\/*[0-9]{1,}*/ {print $0}' file1 > file2

However, it is just printing out every single line in the file. Any help is appreciated.
:confused:

This should work. No need print, since print $0 is default action.

awk -F\| '$9 ~ /\/.*[0-9]+/' file1 > file2

The * here \/* makes / optional. 0 or more hits. Remove this.
Same here: [0-9]{1,}*. Replace with + (1 or more number)
{1,} this does not work if you do not have --posix option. awk --posix code . At lest for my version.

1 Like

That makes a lot more sense. I was wondering why it was just grabbing everything. I totally forgot that the "asterisk" matched 0 or more references and that I needed to add the "dot".

Thanks so much. Sometimes you just need a second set of eyes.

You are welcome :slight_smile:

.* match any or 0 characters after /
[0-9]+ one or more number.