I am trying to execute awk on something like this :

<tag x="whatever" y="http://mysite.com/somewords/word1/word2/word3/word4">

I would like to extract word2 which comes forever after word1, knowing that somewords does not always exist.

I was able to do it using awk, but I used it 3 times, each time with one delimiter.

Is there any way to merge multiple awk commands with multiple delimiters, or simply one awk command to pick out word2?

  • 1
    Why not posted the awk codes you wish to merge?
    – manatwork
    Nov 4, 2013 at 16:34

1 Answer 1


The awk delimiter can be a regular expression, so if you want to split the line on, say, spaces and slashes, you can use -F '[ /]'

But, given your sketchy description, you may just need this:

awk -F/ '{for (i=1; i<NF; i++) if ($i == "word1") {print $(i+1); break}}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .