Unix / Linux Shell: Get Third Field Separated by Forward Slash (/) Delimiter

To extract the third field separated by forward slash (/) delimiter in Unix/Linux shell, you can use the following command:

echo "field1/field2/field3/field4" | awk -F'/' '{print $3}'

This uses the awk command to split the input string on forward slashes (/) and then prints the third field ($3). The -F option is used to specify the field delimiter.

You can replace "field1/field2/field3/field4" with your actual input string, and adjust the field number as needed.

Leave a Comment