I run two awk
command consecutively to break down a string based on multiple delimiters. I am wondering if they can be combined into a single command.
Input data (jot -w "some string, this is number " 10
):
some string, this is number 1
some string, this is number 2
some string, this is number 3
some string, this is number 4
some string, this is number 5
some string, this is number 6
some string, this is number 7
some string, this is number 8
some string, this is number 9
some string, this is number 10
This is just example data, but I want to be able to split the string first based on the comma and then extract the number (fourth word) from the second part. In practice, the number of spaces in the first part of the string could vary, i.e. the following would be valid input:
some string, this is number 1
some string with more spaces, this is number 2
The following command works fine:
$ jot -w "some string, this is number " 10 | awk -F ',' '{print $2}' | awk -F ' ' '{print $4}'
1
2
3
4
5
6
7
8
9
10
Is there any simple way to combine both these commands into a single one?