1

I have the data as below:

p_id^|^data1^|^data2^|^data3

I need to get the 2nd field only

data1

Tried multiple tricks with awk command, but unable to find it out. Can someone please help.

4

Since the separator contains more than one character and all of them are special (both ^ and | are regular expression operators), you need to escape them. On the command line, you would do this with

awk -F '\\^\\|\\^' '{ print $2 }' file

You need the double backslashes to escape the backslashes themselves too (for a different reason).

1
  • Thank you ! Great Help !
    – PriB
    Dec 26 '19 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.