cut with delimiter respect text

Hi,
Can someone help me to get the shortest command

Input file

I|know|"english|french"
It|can|have|four|delimiters

Desired output

"english|french"
have

If I use cut -d "|" -f3 , i am getting "english as 3rd field.But I would like to get the whole text in quotes("") as 3rd field. I have this problem only in 3rd field. Any help is higly appreciated. Thank you,

Initially, i tried to convert all | symbols within quotes to # and to use the CUT -d "|" to extract the 3rd field, then again replace back all # to |. But it is very lengthy, Any short and efficient command is very helpful,

Cheers,

Your file isn't really pipe-delimited if it has pipes in the fields.

You can kludge around this by using " as a delimiter and replacing the problem characters inside. Then you can cut as you please. This has the useful side-effect of removing the quotes, too.

You can do this all in a single awk to cut down on the pipe chain. Not exactly a one-liner but it's still just one command.

$ echo "I|know|\"english|french\"" | awk -F'"' '{
        for(N=2; N<=NF; N+=2) gsub(/[|]/, "#", $N);
        split($0, A, "|");
        gsub(/#/, "|", A[FIELD]);
        print A[FIELD] }' OFS="" FIELD=3

english|french

$

Hope this helps:

cat file 
I|know|"english|french"
It|can|have|four|delimiters

awk -F'"' '{print "\""$2"\"";getline;gsub(/\|/, " ");split($1,array," ");print array[3]}' file 

"english|french"
have