Split string on a backslash (“\”) delimiter in awk?

后端 未结 5 984
花落未央
花落未央 2021-01-14 17:56

I am trying to split the string in a file based on some delimiter.But I am not able to achieve it correctly... Here is my code below.

awk \'var=split($2,arr,         


        
5条回答
  •  悲哀的现实
    2021-01-14 18:54

    As some of the comments mentioned, you have nested single quotes. Switching one set to use double quotes should fix it.

    awk 'var=split($2,arr,"\"); {print $var}' file1.dat
    

    I'd prefer piping to another awk command to using split.I don't know that one is better than the other, it is just a preference.

    awk '{print $2}' file1.dat | awk -F'\' '{...}'
    

提交回复
热议问题